How to underline part of the title (e.g. 40px)?

Is it possible that in simple CSS there is a header, partially emphasized only, in particular, first 50px on the left?

+4
source share
3 answers

You can use a pseudo-element :beforeand 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>
Run codeHide result
+8
source

Use pseudo-element:

h1 {
  position: relative;
}
h1::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: 50px;
  height: 2px;
  background-color: green;
}
<h1>foobar</h1>
Run codeHide result
+7
source

You can add a pseudo-element containing several inextricable spaces that are underlined. This way you get a real underline instead of a border. However, it will still cross letters like "g".

h1::before {
  content:'\a0\a0\a0\a0\a0\a0\a0\a0';
  display:block;
  position:absolute;
  text-decoration:underline;
  width:50px;
  overflow:hidden;
}
<h1>Headline</h1>
<h1>Another Headline</h1>
Run codeHide result
+1
source

All Articles