JSFiddle - React, Tailwind, and code Playground

by hammerbrostime

HTML

<div class="container">
    <h2>This is a very long heading that should wrap with ellipsis when too long, but have a button to it's right.</h2>
    <button>Hello.</button>
</div>

<div class="container">
    <h2>This is short.</h2>
    <button>Sup</button>
</div>

CSS

.container {
    display: inline-block;
   max-width:100%;
   position: relative;
}
h2 {  
    padding-right: 200px;
    box-sizing: border-box;
    
    overflow: hidden; 
    white-space: nowrap; 
    text-overflow: ellipsis; 
    word-break: break-all; 
    word-wrap: break-word; 
    /*display: inline-block; */ 
    display:block;

    /*width: 100%;*/
    width:auto;
   
    
    
}

button {
    position: absolute;
    width: 100px;
    right: 95px;
    top: 2em;
}