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.

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

              
                <h2>The idea here is:</h2>
<ul>
  <li>Only the left-most text should truncate when there is not enough room to display it</li>
  <li>Before any text truncates, each text node should but-up next to each other and occupy any remaining space</li>
  <li>Each text node can NOT have a set width (fixed or flexible) because the length of the text can vary</li>
</ul>
<div class="container">
  <div class="text left">This <strong>should truncate</strong> and align left</div>
  <div class="text middle">This should align left</div>
  <div class="text right">This should align right</div>
</div>
<p>This is easily do-able with flexbox, but what about a fallback for none flexbox browsers?<br>For none flexbox browsers, we CAN apply a width to any of the text elements (and just accept that it may truncate too early). But to do this, we need a different DOM structure. So using the DOM structure below, acheive the same layout as above (using Flexbox).</p>

<h2>None Flexbox Browsers <i style="font-weight: normal;">but still using flexbox</i></h2>
<div class="container2">
  <div class="left-wrap">
    <div class="text left">This <strong>should truncate</strong> and align left</div>
    <div class="text middle">This should align left</div>
  </div>
  <div class="text right">This should align right</div>
</div>
<p>Solved! - See CSS</p>

              
            
!

CSS

              
                // stupid resets
* {
  box-sizing: border-box;
}
body {
  font-family: Sans-serif;
  padding: 50px;
  font-size: 16px;
  line-height: 22px;
  color: #333;
}
h2 {
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 22px;
}
p {
  margin-bottom: 22px;
}
ul {
  margin-bottom: 22px;
  list-style: disc outside;
  padding-left: 22px;
}
strong {
  font-weight: bold;
}
i {
  font-style: italic;
}

// Okay, let's go...
.container {
  background: #222;
  padding: 0 5px;
  height: 30px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  
  .text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 5px;
  }
  .left {
    flex: 0 1 auto;
    color: tomato;
  }
  .middle {
    flex: 1 0 auto;
    color: limegreen;
  }
  .right {
    flex: 0 0 auto;
    color: skyblue;
  }
}

.container2 {
  background: #222;
  padding: 0 5px;
  height: 30px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  
  .left-wrap {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    display: flex; // this is needed
  }
  .right {
    flex: 0 0 auto;
    color: skyblue;
    padding-left: 10px;
  }
  
  .left {
    color: tomato;
    display: inline-block;
    vertical-align: top;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .middle {
    color: limegreen;
    display: inline-block;
    vertical-align: top;
    padding-left: 10px;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console