CSS: centered heading over multible lines, underline just the bottom words

Hey everyone!

I´m happy to be a new member of this forum. I have invested much time, but I cannot find a solution to make the CSS underline like the following picture:

Here how it should look:

It is a heading with centered text. At bigger screens, the text is displayed in just one line.

It would be nice if the red underline isn´t directly connected with the words (so that it behaves responsively).

Have you a CSS snippet or a link?

Thanks in advance & best regards!

Which challenge are you up to?

“text-decoration: underline;”

Did you make the picture or was it a screenshot from a working website? If from a website, use the dev tools in your browser to inspect the element to see what the code is.

Would that break line like the image shows? The line looks to be lower than a typical underline. Maybe some kind of :after code is being used.

Right, text-decoration: underline doesn´t work in that case…

The Screenshot is made by powerpoint :slight_smile:

I worked it out.
Put the text into a <span></span> apply a bottom border to the span and add a white background in your CSS. You can add padding to the span to increase the distance between the bottom of the text and the underline. You can experiment with line-height: as well.


1 Like

Very nice, thank you for the solution!

1 Like

If someone will redo this, here is my final css code:

	background-color: white;
	border-bottom: 1px solid #C81A2E;
	color: #000000;
	font-size: 21px;
	padding-top: 6px;
	line-height: 1.3;
	padding-bottom: 4px;

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.