
It would be cool if there was such an option, else I’d have to overlap the border-bottom with another div..
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDIT: What I’d do these days if there’s a bit more in terms of the element’s text content is use
box-shadowandbackground-clip. Otherwise, see the last solution in my original answer.Let’s dissect the above.
First off,
border-bottom: solid .75em transparent.The
border-bottomarea is going to be the gap area. That’s why we make it transparent. Changing the width of this border changes the width of the gap.The
margin,widthandheightrules – nothing strange here, just positioning and sizing the element.Then we have this bit:
box-shadow: 0 1px 0 -1px black.This
box-shadowwith no blur creates the bottom border. Theyoffset (second value) creates a1px"border". Increasing thisyoffset increases the width of our "border". This is ablackborder, but we could change that to anything else.We also don’t want our box-shadow to show up on the sides, so we give it a
-1pxspread.Finally, we set a
backgroundon our element. It’s adimgreyone, but it could be anything else (a gradient, a picture, whatever). By default backgrounds extend under the border as well, but we don’t want that, so we limit it to the area of thepadding-box. I’ve used the shorthand here. The longhand property isbackground-clipand you can find a detailed explanation for how it works and other examples similar to this one in this article (disclaimer: I wrote it).Here is the original answer
You could use a pseudo element. Absolutely positioned, 100% width, offset below the bottom of the element.
demo
HTML:
CSS:
Or you could use
background-clip: content-boxand you won’t need to use a pseudo-element. But then your text will stick to the edges of the background (unless it’s a small text and centred).demo
Relevant CSS: