Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h5>DEMO</h5>
<h1>Using Container Query on a List of Quotes</h1>
<p><a href="https://developers.hubspot.com/blog/help-prevent-bad-design-using-container-queries-to-style-modules">Read Supporting Article</a> on the HubSpot Developer Blog. Written by <a href="https://bootstrapcreative.com/about/">Jake Lett</a></p>
<p>The animation demonstrates how the styles change based on the container width instead of the window width.</p>
<div class="controls"><button id="play">Play Animation</button> <button id="stop">Stop Animation</button></div>

<div class="testimonial__list animate" id="animation">
   <blockquote class="testimonial__list-item">
      <p>But thinking only of pages limits our potential to address design challenges at a lower level. Sure, starting with a page design may make sense. But by the time you start on the second page, the mindset should shift to looking for reusable chunks. By the third, fourth, and fifth page designs, reusable components become increasingly obvious.</p>
      <cite><img src="https://m.media-amazon.com/images/I/21XBCgr-sXL._SY210_CR52%2C0%2C210%2C210_.jpg" alt="Nathan Curtis"> Nathan Curtis, <a href="https://www.amazon.com/Modular-Web-Design-Components-Documentation-ebook/dp/B003FJ64EE/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=1681204585&sr=8-1">Modular Web Design</a></cite>
   </blockquote>
   <blockquote class="testimonial__list-item">
      <p>A module is a reusable building block that can be added to templates and pages. While a
         module instance is the individual rendered modules on the page. They can have separate field values and as a result look different from other module instances that are for the same module.</p>
      <cite><img src="https://www.hubspot.com/hubfs/HubSpot_Logos/HubSpot-Inversed-Favicon.png" alt="HubSpot icon"> <a href="https://developers.hubspot.com/docs/cms/building-blocks/modules">developers.hubspot.com</a></cite>
   </blockquote>
   <blockquote class="testimonial__list-item testimonial__list-item--featured">
      <p>Modular web design requires more testing and development time to build a solution for a broader set of widths, not just the viewport width.</p>
      <cite><img src="https://i0.wp.com/bootstrapcreative.com/wp-bc/wp-content/uploads/2022/08/jake-lett-2022.png?resize=150%2C150&ssl=1" alt="Jake Lett HubSpot Developer"> Jake Lett, <a href="https://www.bootstrapcreative.com/jake-addons/modular-manifesto">Modular Web Design Manifesto</a></cite>
   </blockquote>
   <blockquote class="testimonial__list-item">
      <p>Understanding modules is key to understanding the HubSpot CMS and its power. Modules are reusable components that can be used in templates or added to pages through drag and drop areas and flexible columns.</p>
      <cite><img src="https://www.hubspot.com/hubfs/HubSpot_Logos/HubSpot-Inversed-Favicon.png" alt="HubSpot icon"> <a href="https://developers.hubspot.com/docs/cms/building-blocks/modules">developers.hubspot.com</a></cite>
   </blockquote>
   <blockquote class="testimonial__list-item">
      <p>A component library isn’t about limiting innovation. Instead, it empowers designers to reuse solutions to problems that have already been solved so they can focus more on the problems that don’t have solutions. When individuals no longer reinvent vast portions of a design with every project, productivity increases and headaches diminish. In addition, a library provides a platform for improved governance, a deeper baseline for collaboration, and a structure for useful and predictable documentation.</p>
      <cite><img src="https://m.media-amazon.com/images/I/21XBCgr-sXL._SY210_CR52%2C0%2C210%2C210_.jpg" alt="Nathan Curtis"> Nathan Curtis, <a href="https://www.amazon.com/Modular-Web-Design-Components-Documentation-ebook/dp/B003FJ64EE/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=1681204585&sr=8-1">Modular Web Design</a>
   </blockquote>
</div>

<p><a href="https://bootstrapcreative.com/about/">©2023 Bootstrap Creative</a></p>
              
            
!

CSS

              
                .testimonial__list {
   border: 10px solid rgba(150, 200, 200, 0.4);
   padding: 2rem;
   margin-bottom: 2rem;
   display: flex;
   flex-direction: row;
   flex-wrap: wrap;
   width: 100%;
   gap: 2%;
   container-type: inline-size;
   container-name: list;
   /* shorthand - container: list / inline-size;  */
}

.testimonial__list-item {
   quotes: "“" "”" "‘" "’";
   width: 49%;
   line-height: 1.2;
   box-sizing: border-box;
   margin-bottom: 2rem;
   container-type: inline-size;
   container-name: item;
   /* shorthand - container: item / inline-size;  */
}

.testimonial__list-item p {
   background-color: #e4e4e7;
   padding: 1rem 1.5rem;
   quotes: "“" "”" "‘" "’";
   border-radius: 20px;
   font-style: italic;
}

.testimonial__list-item p::before {
   content: open-quote;
   font-weight: bold;
   opacity: 0.5;
   margin-left: -0.5rem;
}

.testimonial__list-item p::after {
   content: close-quote;
   font-weight: bold;
   opacity: 0.5;
}

.testimonial__list-item img {
   max-width: 80px;
   border-radius: 50%;
   border: 2px solid orange;
}

.testimonial__list-item--featured {
   width: 100%;
}

.testimonial__list-item cite img {
   margin-right: 0.5rem;
}

/* If quote list container is less than 500px wide */
@container list (max-width: 500px) {
   .testimonial__list-item {
      width: 100%;
   }

   .testimonial__list-item cite {
      text-align: center;
      display: block;
   }

   .testimonial__list-item cite img {
      display: block;
      margin: 0 auto;
   }
}

/* If a quote item is larger than 500px */
@container item (min-width: 500px) {
   .testimonial__list-item p {
      font-size: 1.5rem;
      font-weight: 600;
   }
}

/* If a quote item is larger than 960px */
@container item (min-width: 960px) {
   .testimonial__list-item p {
      background-color: #dbeafe;
      font-size: 2rem;
   }
}

/* On mobile - increase all font sizes so its easier to read */
@media screen and (max-width: 500px) {
   .testimonial__list-item {
      font-size: 1.5rem;
   }
}

/* styles only used for the demo */
body {
   padding: 2rem;
}
.controls {
   margin-bottom: 1rem;
}
.testimonial__list.animate {
   animation: w100 10s 5 ease-in-out alternate;
   animation-timing-function: ease-in-out;
}
@keyframes w100 {
   0% {
      width: 20%;
   }

   /* Finish changes by here */
   70% {
      width: 100%;
   }

   /* Between 20% and 100%, nothing changes */
   100% {
      width: 100%;
   }
}
/* end demo styles */

              
            
!

JS

              
                // play animation
document.querySelector("#play").addEventListener('click', function() {
	document.querySelector("#animation").classList.add("animate");
});

// stop animation
document.querySelector("#stop").addEventListener('click', function() {
	document.querySelector("#animation").classList.remove("animate");
});
              
            
!
999px

Console