#full-service-creative-studio::after {
content: "";
position: absolute;
left: 20px;
bottom: 10px;
width: 103%;
height: 28px;
background: #46989C;
z-index: -1;
}
<h1 id="full-service-creative-studio">Full Service Design Studio</h1>
Currently it works great for a single line but then when we scale down to say mobile view it only underlines the bottom line of the text. is there a way to make it underline every line?
4
Answers
I think what you are looking for is:
The pseudo selector
::after
will put the line underneath theh1
ELEMENT_NODE
and not theTEXT_NODE
contained within theh1
element.You need is a css class
currently, you are using an
id
selector to apply the css that is why it is only applying to a single line, using aclass
as a selector you can apply the same style to multiple elements.Crux is that CSS
id
selector is used to find only 1 element. whileclasses
are used to apply common styles across various HTML tags.Hope this w3school link helps you understand
The hardest part (which every other answer ignores) is the
left
offset you have on the underline element, as well as the103%
length.You can use a data-attribute, pseudo element,
text-decoration
andtext-underline-offset
to handle this.These are not perfect by any means, but gets you kind of close – and may give you an idea.
The title says "tweak code", so this adds a
data-attribute
to theH1
tag with the same title content. We then style the::after
pseudo with everything to push the line left. The problem with this, is that at certain breakpoints the pseudo element will wrap before the visible text, creating a hanging underline.I don’t think you can get this right, unless the whole underline can be left of the content (see the second example) – which again, gets close:
Number 2