Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overflow: hidden behind padding

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;
}
like image 944
developthewebz Avatar asked Oct 15 '15 14:10

developthewebz


People also ask

How can I hide my padding overflow?

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.

Why is padding causing overflow?

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.

What is the overflow hidden?

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.


1 Answers

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>
like image 133
Dominic Avatar answered Oct 10 '22 11:10

Dominic