Is it possible to define where overflow: hidden begins based on padding?
For example, I currently have a table in which I have a long string. There is padding on the left, but the length of the string exceeds the td, so overtflow hidden is triggered. I would like the overflow: hidden to trigger at the beginning of the padding rather than the end of the td.
Essentially I would like the overflow: hidden to begin at the start of the far right red line.
.order-table td {
padding: 1em 3px;
border-left: #ddd 1px solid;
font-size: 0.9em;
overflow: hidden;
}
To hide overflow from rendering outside the element's box, you can set the overflow property to “hidden.” This will clip the content at the box's padding edge and not allow the user to view the content beyond that edge by scrolling or dragging their finger on a touch screen or any other means.
By default in CSS, an element's actual width and height is width + padding + border. Meaning, when we give an element a width of maybe 10px, the actual width of that element becomes 10px + padding + border. This is why giving it padding or border when it is already at 100% will cause an overflow.
overflow: hiddenWith the hidden value, the overflow is clipped, and the rest of the content is hidden: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.
Simply wrap your content in another element and apply the overflow: hidden
to that instead:
table {
width: 100px;
table-layout:fixed;
}
td {
border: 1px solid red;
padding: 10px;
}
.inner {
border: 1px solid blue;
overflow: hidden;
text-overflow: ellipsis;
}
<table>
<tr>
<td><div class="inner">123456789012345678901234567890</div></td>
</tr>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With