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

Save Automatically?

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

              
                <h1>Flexible Images Example: Starter</h1>

<p>There are Three rules of thumb to keep in mind when using images in responsive, CSS Grid-based layout.</p>

<ol>
  <li>Put images inside of a container</li>
  <li>Add in CSS to stop images from getting larger than their containers</li>
  <li>Don't apply width directly to the image. Let the grid and containers do the work.</li>
</ol>

<p>Here is an example of putting an image in a container</p>

<pre><code>
&lt;figure&gt;
  &lt;img src="https://img/blah.jpg" alt="alternate text"&gt;
&lt;/figure&gt;
</code></pre>

<p>Here is the CSS you need to stop images from getting larger than their container:</p>

<pre><code>
/* ========= Basic Responsive Images  ========= */
img{
  width: auto;
  height: auto;
  max-width: 100%;
}
</code></pre>
<p>You can see this and other base responsive styling at this <a href="https://gist.github.com/profstein/ff67cb749716f2d6a5d95c98350930cb">GitHub Gist</a>.</p>

<h2>Add CSS to this codepen to </h2>

<ol>
  <li>Add the responsive css to stop images getting larger than their containers (hint: copy the CSS for img above and paste it in on line 2 of the CSS).</li>
  <li>Set a grid on the .image-container section.</li>
  <li>Play around with the grid. Change the number of columns and the spans on the .item elements to see how the images respond.</li>
</ol>



<section class="img-container">
  <div class="item one"><img src="https://picsum.photos/1015/540" alt="item one"></div>
  <div class="item two"><img src="https://picsum.photos/850" alt="item two"></div>
  <div class="item three"><img src="https://picsum.photos/630/500" alt="item three"></div>
  <div class="item four"><img src="https://picsum.photos/630/1080" alt="item four"></div>
  <div class="item five"><img src="https://picsum.photos/1200/900" alt="item five"></div>
  <div class="item six"><img src="https://picsum.photos/630/500" alt="item six"></div>
  
</section>
              
            
!

CSS

              
                /* =======Add Basic Responsive Images CSS here ======== */
img{
}

/* ====== CSS For Grid and grid items ====== */

/* this is the grid container */
.img-container{
  
}

/* these are the items */
.item{
  outline: 2px solid black;
}

/* individual items */
.item.one{
  
}

.item.two{
  
}

.item.three{
  
}

.item.four{
  
}

.item.five{
  
}

.item.six{
  
}


/* --- Media Query to change layout --- */

@media screen and (min-width: 800px){
  .img-container{
  
  }

  /* individual items */
  .item.one{

  }

  .item.two{

  }

  .item.three{

  }

  .item.four{

  }

  .item.five{

  }

  .item.six{

  }
  
} /* end media query */
              
            
!

JS

              
                
              
            
!
999px

Console