Fiddle: https://jsfiddle.net/wa51kdh7/
Code:
HTML: Hello world
<span class="span2">
Goodbye cruel world
</span>
CSS:
span {
display: inline-block;
margin: 0;
padding: 0;
line-height: 16px;
font-size: 16px;
height: 16px;
}
.span1 {
background-color: lightblue;
}
.span2 {
background-color: pink;
overflow: hidden;
width: 130px;
text-overflow: ellipsis;
}
Here I am trying to create two spans next to each other, only one of them has overflow: hidden and the other shouldn't have overflow: hidden. For some reason the overflow: hidden affects the heights and they don't line up - even when I use an explicit height.
Any idea how to fix this?
hidden - The overflow is clipped, and the rest of the content will be invisible. scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content. auto - Similar to scroll , but it adds scrollbars only when necessary.
To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.
You can do this by setting the child to be position: absolute. Usually, this should work: overflow: hidden doesn't clip absolutely positioned descendants unless the same container doesn't have position:relative (see cssmojo.com/clearfix-reloaded-overflowhidden-demystified).
The hidden value of the overflow property hides all the content that is exceeding the box area. This property should be handled with care because the content that this property hide is completely invisible to the user, however, it is best suited for displaying content that is dynamic in nature.
This can also be fixed by adding vertical-align: top
to the span
's CSS rule. The reason that both rules fix the problem is that they enforce the vertical alignment of the divs.
Adding a vertical-align
rule will keep you from potentially having the elements that follow from needing to be cleared.
span {
display: inline-block;
margin: 0;
padding: 0;
line-height: 16px;
font-size: 16px;
height: 16px;
vertical-align: middle;
}
Hi I just updated your span
to float: left
and it works. It's not the overflow
but the fact the span
s aren't floated that they are misaligned.
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