Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to underline part of a heading (first 40px for instance)?

Tags:

css

underline

Is it possible in simple CSS to have a heading underlined partly only, specifically first 50px on the left?

like image 871
drake035 Avatar asked Apr 26 '16 09:04

drake035


People also ask

How do you underline headings?

The quickest way to underline text is to press Ctrl+U and start typing. When you want to stop underlining, press Ctrl+U again. You can also underline text and spaces in several other ways.

How do you underline a heading in HTML?

The <u> tag in HTML stands for underline, and it's used to underline the text enclosed within the <u> tag. This tag is generally used to underline misspelled words.

How do you display Heading 1 with an underline using CSS?

How to Underline a Title in CSS. To underline a title, you can use text-decoration: underline; but you can make it prettier if you use the border-bottom property. In the latter case, however, you need to add display: inline; so that the underline wouldn't be longer than the word itself.


1 Answers

You can use the :before pseudo element and add a border to it.

h1 {
  position: relative;
  line-height: 1.2em;
}
h1:before {
  position: absolute;
  left: 0;
  top: 1.2em;
  height: 0;
  width: 50px;
  content: '';
  border-top: 1px solid red;
}
<h1>This is a header, partly underlined</h1>
like image 197
Paul Avatar answered Oct 20 '22 17:10

Paul