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

              
                <table>
    <thead>
        <tr>
            <th>
                <div class="wrap" title="Some long title">Some long title</div>
            </th>
            <th>
                <div class="wrap">Short</div>
            </th>
            <th>
                <div class="wrap">medium one</div>
            </th>
            <th>
                <div class="wrap" title="endlessly super long title which no developer likes to see">endlessly super long title which no developer likes to see</div>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><div class='wrap'>aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp</div></td>
            <td>b</td>
            <td>c</td>
            <td>d</td>
        </tr>
        <tr>
            <td>d</td>
            <td>c</td>
            <td>a</td>
            <td>b</td>
        </tr>
        <tr>
            <td>c</td>
            <td>b</td>
            <td>a</td>
            <td>
              <div class="wrap" title="This is an example of a very long text within a cell which should be trimmed to multiple lines via line-clamp">
                This is an example of a very long text within a cell which should be trimmed to multiple lines via line-clamp
              </div>
          </td>
        </tr>
    </tbody>
</table>

              
            
!

CSS

              
                body{ font:18px Arial; padding:20px; }

table{
    $thead_height : 52px;
    $seperator : 1px solid rgba(#999, .4);

    width: 40%;
    max-width: 1200px;
    margin:1em auto;
    color: #333;
    border: $seperator;
  
    // ALLOW TABLE RESIZING FOR THIS DEMO
   // resize: auto;
    overflow: hidden;


    td, th{ 
      max-width: 10vw;
      text-align: left; 
      padding: 1.2em 20px; 
      border-left: $seperator; 

      &:first-child{ border-left:0; }
    }

    th{
        border-bottom: $seperator;
        font-weight: 700;
        text-transform: uppercase;
    }
  
    td{
      --line-clamp: 2;
    }
  
    .wrap{ 
      display: -webkit-box;
      -webkit-line-clamp: var(--line-clamp, 1);
      -webkit-box-orient: vertical;
      word-break: var(--word-break, 'none');
      overflow: hidden;
    }
}
              
            
!

JS

              
                /*
// From my other pen: 
// https://codepen.io/vsync/pen/BawdgEd
function lineCount(elm) {
      const originalStyle = elm.getAttribute('style')
      
      // normalize (should probably be done to all children also via treeWalker)
      elm.style.padding = 0
      elm.style.border = 0
      const clientHeight = elm.clientHeight
      console.log(getComputedStyle(elm))
                  debugger;
      const initialLineHeight = parseInt(getComputedStyle(elm)['line-height'])
      const adjust = 0;
      elm.style.height = 'auto'
      elm.style.minHeight = '0'  
      elm.style.lineHeight = 1
      
      // measure
      const lineHeight = parseInt(getComputedStyle(elm)['line-height'])
      const scrollHeight = elm.scrollHeight
  
      elm.style.lineHeight = 0
      const singleLineHeight = elm.scrollHeight * 2 
      
      
      
      const lineCount = Math.round(scrollHeight / singleLineHeight)
      const linesFit = Math.floor(clientHeight / (initialLineHeight - adjust))
      
      // undo above style changes
      elm.setAttribute('style', originalStyle)
  
      return {
        lineCount: (isNaN(lineCount) || singleLineHeight == 0) ? 0 : lineCount,
        linesFit
      }
}


const autoClamp = elm => {
 // const isTextClamped = elm.scrollHeight > elm.clientHeight;
  console.log(  lineCount(elm)  )
}

const observer = new ResizeObserver(m => {
  requestAnimationFrame(() => {
    const {target, borderBoxSize} = m[0];
    const wrapElms = target.querySelectorAll('.wrap');
    
    for( const wrappedElm of wrapElms){
       autoClamp(wrappedElm)
    } 
    // console.log(borderBoxSize);
  });  
});

const tableElm = document.querySelector('table');
observer.observe(tableElm, { attributes: true });
*/
              
            
!
999px

Console