I am currently trying to make a custom underline with border-bottom. However, currently the underline is going all the way of my block-element (whole page).
I’d prefer to have it being only 50px longer than my headline (however the text is flexible and I do not know the length).
Can I do this without adding another <span>
tag within the <h2>
somehow? I do not wannt to add a <span>
element to each <h2>
just to change my design.
Current HTML is:
<h1>My title</h1>
CSS:
h1 {
font-size: 18px;
color: #b62525;
border-bottom: 2px solid #c68181;
}
Is it possible to adjust the border-bottom length to my text length? (e.g. behave like inline element for border, but like block for newlines, padding and margin)
You need to put a border-bottom and extend the width of the p where the text exists. Hope this helps. Save this answer.
You should first select the underlined space before the texts, and go to the “Font” dialog box again. Choose “Condensed” under “Spacing” options. And in the “By” box, enter a specific number you want.
You cannot modify the width of underline tag. Instead go for Border-bottom approach and change it's properties as required.
Using display: inline-block
works, the only caveat being that the content after the <h1>
tag must be the full width of the container element. The other solutions here also assume this. You can also use display: inline
(supported by older browsers), but inline-block
allows for setting of explicit widths, should you need it.
Here's a JSFiddle
h1
{
display: inline-block;
padding-right: 50px;
border-bottom: 1px dotted #888;
}
Inline or floating methods can be problematic if you're unable to compensate for them in other rules. One alternative is to use display:table
h1
{
display:table;
border-bottom:1px solid black;
padding-right:50px;
}
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