- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hello All,
1 – Could someone explain why span tag is overlapping the <hr> element tag?
2 – The desired result is achieved by setting display property to inline-block or setting high line-height value.
3 – How can I fix this issue without setting display to inline-block.
Thanks.
Demo: http://codepen.io/anon/pen/qEMyOg
Because padding on inline elements is kind quirky…adding increased the visual size but does nothing to affect the block context of the span
…as such it doesn’t move. It’s in the CSS2 spec.
You can find a whole article on it at http://maxdesign.com.au/news/inline/..but the important parts are:
The W3C’s CSS2 spec states that for Inline, non-replaced elements, the ‘height’ property doesn’t apply, but the height of the box is given by the ‘line-height’ property.
While padding can be applied to all sides of an inline element, only left and right padding will have an effect on surrounding content.
What’s wrong with inline-block
…it seems to be exactly what you are looking for?
Since we know this:
height of the box is given by the ‘line-height’ property.
We can use calc
to play with line-height like this
span {
background: red;
padding: 25px;
line-height: calc(1em + 50px);
}
Thanks for the info and the link. I just wanted to know that are there any other ways to fix the issue without using display or line-height property.
I just wanted to know that are there any other ways to fix the issue without using display or line-height property.
Basically…no. That’s that nature of inline elements. Annnoying perhaps but that where we are.