Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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>Petit défi de @HTeuMeuLeu</h1>
<p><a href="https://twitter.com/HTeuMeuLeu/status/430821230304690176">Vous confirmez que ceci est bien un casse-tête ? (et que je ne suis pas passé à côté d'une solution simple)</a><br /><a href="#img">Voir l'image</a></p>
<p>Cette solution me semble proche du but&hellip; </p>
<p>La grille est fluide, les éléments verts font 200px de large, la gouttière est de 20px, item1 et item5 à gauche ; item4 et item8 à droite.</p>
<p>L'idée ici est de "tricher" sur la largeur des li et d'ajuster avec des media-queries</p>
<p>En mobile-first, passage d'1 colonne, à 2, puis 4.<br/>Dès qu'il y a 4 colonnes ajustement des largeurs des cellules pour avoir une différence de marge (gris) la moins visible possible.</p>
<ul>
  <li id="js-li1">
    <div>item1</div>
  </li><li id="js-li2">
    <div>item2</div>
  </li><li>
    <div>item3</div>
  </li><li>
    <div>item4</div>
  </li><li>
    <div>item5</div>
  </li><li>
    <div>item6</div>
  </li><li>
    <div>item7</div>
  </li><li>
    <div>item8</div>
  </li>
</ul>
<p>Largeur du body ; des li et marges (espace visible en gris) <strong>Valable uniquement lorsqu'il y a 4 colonnes</strong></p>
<div id="js-wwidth"></div>
<div id="w"></div>
<p id="img">
  <img src="https://pbs.twimg.com/media/BfqVoE_CEAAlTlR.png:large" alt="défi css" />
</p>


              
            
!

CSS

              
                *{
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html, body{
  margin: 0;
  padding: 0;
}
img{
  max-width: 100%;
  height: auto;
}
ul{
  display: block;
  margin: 0;
  padding: 0;
  margin-left: -20px;
}
li{
  display: inline-block;
  vertical-align: top;
  margin: 0;
  padding: 0;
  padding-left: 20px;
  width: 100%;
  margin-top: 20px;
  background: #ececec;
  background-clip: content-box;
  text-align: center;
}
li>div{
  width: 200px;
  max-width: 100%;
  display: block;
  margin: 0 auto;
  padding: 20px;
  background: #bada55;
  text-align: center;
}
@media (min-width:400px){
	li{
  width: 50%;
  }
}
@media (min-width:800px){
	li{
  width: 25%;
}
}
@media (min-width:860px){
li{
  width: 26%;
}
li:nth-child(4)
, li:last-child{
  width: 24%;
}
li:nth-child(5)
, li:first-child{
  width: 24%;
}
li:nth-child(4) div
, li:last-child div{
  margin-right: 0;
}
li:nth-child(5) div, li:first-child div{
  margin-left: 0;
}
}
@media (min-width:1060px){
li{
  width: 27%;
}
li:nth-child(4)
, li:last-child{
  width: 23%;
}
li:nth-child(5)
, li:first-child{
  width: 23%;
}
}
@media (min-width:1320px){
	li{
  width: 28%;
}
li:nth-child(4)
, li:last-child{
  width: 22%;
}
li:nth-child(5)
, li:first-child{
  width: 22%;
}
}

              
            
!

JS

              
                function getWidth(){
document.getElementById('js-wwidth').innerHTML = document.body.offsetWidth;
var l1 = document.getElementById('js-li1'). getBoundingClientRect().width-20;
var l2 = document.getElementById('js-li2').getBoundingClientRect().width-20;
  document.getElementById('w').innerHTML = '';
  document.getElementById('w').innerHTML += '<br/>Au bord : ' + l1 +'px , marge : '+ (l1-200) +'<br/>Au centre : '+ l2 +'px , marge : '+ (l2-200)/2 +'' ;
}

getWidth();

window.onresize = function(){getWidth()}

              
            
!
999px

Console