- So i would like to add a border to a h3 tag.
- This border needs to span the width of the longest part of the visible text and no futher.
- Currently this border seems to span the entire width of the wrapping div.
Seems weird to me that adding display inline block to a h tag doesn't provide me with the results I was after.
div {
max-width: 180px;
}
h3 {
display: inline-block;
border-bottom: 2px solid green;
}
<div>
<h3>Lorem Ipsum Dolar.....</h3>
</div>
EDIT: Seems that some of you don't get that the max-width is required.
This is how it sould line up.
Hmmm... Seems that a perfect solution isn't possible with CSS. But I've used @Muhammad Usman example and added bottom: -120%;
and replaced the height and background with border properties. which works for 2 lines of text.
div {
max-width: 200px;
border: dashed 1px grey;
}
h3 {
display: inline;
font-size: 1.6em;
position: relative;
}
h3::after {
border-bottom: 4px solid green;
bottom: -120%;
content: "";
left: 0;
position: absolute;
right: 0;
}
<div>
<h3>Lorem Ipsum Dolar</h3>
<p>Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet Lorem ipsum dolar set ammet</p>
</div>