0

How can I draw a line like after title text like this :

"TITLE ________"

In CSS?
The "_" should complete the rest of the div and fill the remaining space.

web-tiki
  • 99,765
  • 32
  • 217
  • 249
Olaf
  • 95
  • 2
  • 3
  • 8

3 Answers3

14

Based on this answer :

h1{
  overflow:hidden;
}
h1:after{
  content:'';
  display:inline-block;
  width:100%; height:100%;
  margin-right:-100%;
  border-bottom:1px solid #000;
}
<h1>Title</h1>
<h1>Longer Title</h1>
Community
  • 1
  • 1
web-tiki
  • 99,765
  • 32
  • 217
  • 249
  • Ok it's completely what i need there is other solution compatible with IE 6 ? Tanks – Olaf Jun 01 '15 at 13:50
  • @Olaf please dont send in tanks! and pseudo elements are not supported in ie6, and there aren't many people using ie6 – Max Payne Jun 02 '15 at 02:58
  • what if we have 2 line heading. the line should fill first line as suggested by your answer and second line should fill whole space. see this link for reference image. https://i.stack.imgur.com/yQ4gJ.jpg – Assad Nazar Aug 14 '18 at 17:49
4

h1 {
  position: relative;
}

h1:after {
  content: "";
  position: absolute;
  border-bottom: 1px solid red;
  width: 100%;
  bottom: 0;
}
<h1>Title Here</h1>
adamccfc
  • 224
  • 2
  • 11
-3
h1:after {
    content: "__________________";
}

Further explanation and examples: :after pseudo class

Der Vampyr
  • 941
  • 1
  • 7
  • 13