123

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="container">
  <!-- Maurice -->
  <div class="parent">
      <div class="monkey-container">
        <img class="monkey" src="http://www.baillement.com/images/bonobo.gif"/>
      </div><!--
      --><div class="banana">
        Banane
      </div>
  </div>

  <!-- Jean-Michel -->
  <div class="parent">
      <div class="monkey-container">
        <img class="monkey" src="http://a137.idata.over-blog.com/4/41/01/27/siamang-hurle.jpg"/>
      </div><!--
      --><div class="banana">
          <div>épluchure 1</div>
          <div>Banane</div>  
      </div>
  </div>

  <!-- René -->
  <div class="parent">
      <div class="monkey-container">
        <img class="monkey" src="http://p2.storage.canalblog.com/22/05/544524/35047908.jpg"/>
      </div><!--
      --><div class="banana">
        Banane
      </div>
  </div>

   <!-- Chantale -->
  <div class="parent">
      <div class="monkey-container">
        <img class="monkey" src="https://s-media-cache-ak0.pinimg.com/236x/c2/5c/a9/c25ca92701b919a9137fff75bf23a9a9.jpg"/>
      </div><!--
      --><div class="banana">
        Banane
      </div>
  </div>
</div>
            
          
!
            
              .parent {
	   margin: 20px auto;
	   width : 465px;
	   border-top: 1px solid #c6c6c6;
	   border-bottom: 1px solid #c6c6c6;
	   padding: 15px 30px;
}
.monkey {
	   /* pour que l'image soit homothétique */
	   height: auto;
	   /*mais jamais plus grande que sa taille d'origine */
 	  max-width: 100%;
}
.banana {
	   font-family: Arial,Helvetica Neue,Helvetica,sans-serif;
	   color: #d1d30c;
	   font-size: 40px;
 	  line-height: 46px;
}


#container {
    /* égal à 2 fois la largeur d'un parent */
    width: 930px; 
    margin: 0 auto;
}
#container::after {
    /* on fait un petit clearfix */
    display: table;
    content: '';
    float: none;
    clear:both;
}
.parent {
	float: left;
	width: 48%;
 	 /* permet que le padding face parti des 48% de width */
	box-sizing: border-box;
  	-webkit-box-sizing: border-box;
  	-moz-box-sizing: border-box;
  	-ms-box-sizing: border-box;
 	 -o-box-sizing: border-box;
}


.parent:nth-child(2n+0){
  /* les 2% restants sont un margin */
  margin-left: 4%;
}

.monkey-container,
.banana {
	display: inline-block;
	vertical-align: middle;
	width: 50%;
	padding: 20px;
	/* permet que le padding face parti des 50% de width */
	box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
}



.monkey-container {
	/* on remet le line-height d'origine */
	line-height: 15px;
}


.banana {
	/* idem ici */
	line-height: 54px;
}
            
          
!
            
              $(document).ready(function(){

/* on déclare les variables au fur et à mesure au dessus pour ne pas avoir à les déclarer à chaque boucle */
  var $container = $('#container'),
      height  = 0,
      firstHeight = 0,
      padding = 0,
      $elems = $();
  
  
  /* pour chaque parent présents dans le container */
  $container.find('.parent').each(function(key,value){
      height = $(this).height();
      /* on stock l'élément */
      $elems = $elems.add($(this));
      /* nous lançons la routine tous les 2 éléments */
      if(key%2 == 0){
        // on stocke la première hauteur 
        firstHeight = height;
      }else{
        // si la hauteur précédente est la plus grande, nous l'utilisons 
        if(firstHeight > height){
            height = firstHeight;
        }

        /* ici le padding nous embête, il faut le comprendre dans la hauteur (2 fois, le margin-top et bottom) c'est à cause du box-sizing...*/
        padding = parseFloat($(this).css('padding'))*2;

        
        $elems.css({
           'height' : height + padding + 'px',
            'line-height' : height +'px',
        });

        /* on vide la collection pour les suivants */
        $elems = $();
      }
  });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console