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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

            
              
<p class="panel row">See: <a href="https://css-tricks.com/flexbox-truncated-text/">https://css-tricks.com/flexbox-truncated-text/</a></p>

<p class="row">Text truncates as expected when it is directly within the flex item.</p>

<div class="row">
   <div class="flex flex--text-directly-within-flex-child">
      <div class="flex__item">This is flex item 1 which should truncate text</div>
      <div class="flex__item">This is flex item 2 which should truncate text</div>
      <div class="flex__item">This is flex item 3 which should truncate text</div>
      <div class="flex__item">This is flex item 4 which should truncate text</div>
   </div>
</div>

<p class="row">When the flex item contains a child element that has text, the text does not truncate.</p>

<div class="row">
   <div class="flex flex--truncation-broken">
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 1 which should truncate text but instead breaks the layout</p>
      </div>
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 2 which should truncate text but instead breaks the layout</p>
      </div>
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 3 which should truncate text but instead breaks the layout</p>
      </div>
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 4 which should truncate text but instead breaks the layout</p>
      </div>      
   </div>
</div>

<p class="row">Setting <code>min-width: 0;</code> on the flex item fixes the issue.</p>

<div class="row">
   <div class="flex flex--truncation-fixed">
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 1 fixed for truncation</p>
      </div>
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 2 fixed for truncation</p>
      </div>
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 3 fixed for truncation</p>
      </div>
      <div class="flex__item">
         <p>Child &lt;p&gt; element of flex item 4 fixed for truncation</p>
      </div>      
   </div>
   </div>
</div>

            
          
!

CSS

            
              * {
   margin: 0;
   padding: 0;
   box-sizing: border-box;
}

body {
   padding: 32px 8px;
   font-family: sans-serif;
   color: #333;
   margin: 0 auto 32px auto;
   max-width: 590px;   
}

@mixin truncate-text() {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.row {
   margin-bottom: 2em;
}

.flex {
   display: flex;
   flex-wrap: wrap;
   margin-left: -2%;
   margin-bottom: -2%;
   background-color: #eee;  
   
   &__item {
      flex: 1 0 48%;
      margin-left: 2%;
      margin-bottom: 2%;
      padding: 16px;
      background-color: #ccc;
      color: #666;
   }
}

.flex.flex--text-directly-within-flex-child {      
   .flex__item {      
      @include truncate-text();
   }
}

.flex.flex--truncation-broken {
   .flex__item {      
      p {
         // truncating text does not work
         @include truncate-text();
      }
   }
}

.flex.flex--truncation-fixed {
   .flex__item {
      // setting min-width on the flex item fixes the truncation
      min-width: 0;   
      p {
         @include truncate-text();
      }
   }
}

.panel {
   padding: 1em;
   background-color: #50738c;
   color: #fff;
   
   a {
      color: #fff;
   }
}

            
          
!

JS

            
              
            
          
!
999px

Console