css - How to add ellipses without fixing the width? -
.nowrap { overflow: hidden; white-space: nowrap; /*width: 300px;*/ text-overflow: ellipsis; } .body { color: #777; } table { border-collapse: collapse; } td, th { border: 1px solid black; text-align: left; } <table> <thead> <tr> <th>from</th> <th>subject/body</th> </tr> </thead> <tbody> <tr> <td>mark</td> <td><div class="nowrap"><span class="subject">lorem ipsum</span> <span class="body"> – lorem ipsum dolor sit amet, consectetur adipiscing elit. integer tincidunt aliquet libero quis tempus. vivamus id est purus. nulla augue neque, vestibulum in vestibulum vitae, ornare vel nisi. nullam non dolor tincidunt, mattis metus ac, feugiat sapien. interdum et malesuada fames ac ante ipsum primis in faucibus. integer mollis leo in tristique consectetur. quisque non imperdiet neque. nunc fermentum neque sit amet nulla interdum vestibulum. sed ac tempus dolor.</span></div> </td> </tr> </tbody> </table> how can keep subject/body on 1 line, ellipses @ end, without fixing width of container?
if ellipses aren't possible, how @ least keep wrapping?
to prevent ellipsis overflows in table cell, set <table> table-layout:fixed , width:100%, , set fixed/percentage width on first column.
table { border-collapse: collapse; table-layout: fixed; width: 100%; } th:first-child { width: 50px; } table { border-collapse: collapse; table-layout: fixed; width: 100%; } th, td { border: 1px solid black; text-align: left; } th:first-child { width: 50px; } .ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } <table> <thead> <tr> <th>from</th> <th>subject/body</th> </tr> </thead> <tbody> <tr> <td>mark</td> <td> <div class="ellipsis"> <span class="subject">lorem ipsum</span> <span class="body"> – lorem ipsum dolor sit amet, consectetur adipiscing elit. integer tincidunt aliquet libero quis tempus. vivamus id est purus. nulla augue neque, vestibulum in vestibulum vitae, ornare vel nisi. nullam non dolor tincidunt, mattis metus ac, feugiat sapien. interdum et malesuada fames ac ante ipsum primis in faucibus. integer mollis leo in tristique consectetur. quisque non imperdiet neque. nunc fermentum neque sit amet nulla interdum vestibulum. sed ac tempus dolor.</span> </div> </td> </tr> </tbody> </table> for responsive table layouts, use 2 <div>s, , set them table , table-cell respectively, plus following styles.
.container { display: table; table-layout: fixed; width: 100%; } .ellipsis { display: table-cell; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } table { border-collapse: collapse; } th, td { border: 1px solid black; text-align: left; } .shrink { white-space: nowrap; } .expand { width: 99.999%; } .container { display: table; table-layout: fixed; width: 100%; } .ellipsis { display: table-cell; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } <table> <thead> <tr> <th class="shrink">from</th> <th class="expand">subject/body</th> </tr> </thead> <tbody> <tr> <td class="shrink">mark</td> <td class="expand"> <div class="container"> <div class="ellipsis"> <span class="subject">lorem ipsum</span> <span class="body"> – lorem ipsum dolor sit amet, consectetur adipiscing elit. integer tincidunt aliquet libero quis tempus. vivamus id est purus. nulla augue neque, vestibulum in vestibulum vitae, ornare vel nisi. nullam non dolor tincidunt, mattis metus ac, feugiat sapien. interdum et malesuada fames ac ante ipsum primis in faucibus. integer mollis leo in tristique consectetur. quisque non imperdiet neque. nunc fermentum neque sit amet nulla interdum vestibulum. sed ac tempus dolor.</span> </div> </div> </td> </tr> </tbody> </table>
Comments
Post a Comment