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.

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

            
          
!
            
              // 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;
  }
}

            
          
!
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