Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create border-bottom smaller than element and with thicker middle

Tags:

css

I'm using some stylized HRs to create section separators.

But now I'm trying to create a H1 element with a border bottom smaller than H1 width (variable width according to the width of the H1 text) and with a thicker middle (height).

Something like this:

This is the idea

I scoured several search sources trying to find a solution but found nothing like it.

I tried to use :after and :before but still stuck. Any idea?

What I've tried so far:

h1 {
  display:inline;
  border-bottom:1px solid black;
}

h1:after {
 content: '';
  display: block;
  width: 100%;
  height: 100%;
  border-bottom:3px solid red;
}
<h1>
My Text
</h1>
like image 474
Russel Riehle Avatar asked Jan 03 '23 11:01

Russel Riehle


1 Answers

You can easily do such thing with linear-gradient with no need of extra markup or pseudo element:

h1 {
  display:inline-block;
  font-size:3em;
  padding-bottom:10px;
  background:
   linear-gradient(red 0 0) 50% calc(100% - 2px)/80% 2px,
   linear-gradient(red 0 0) 50% 100%            /40% 6px;
  background-repeat:no-repeat;
}
<h1>Lorem Ipsum</h1>
like image 64
Temani Afif Avatar answered Jan 05 '23 15:01

Temani Afif