Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Limit the bottom bar to the text and not the window width

I’ve this style for my titles on my website:

.heading-text>* {
  position: relative;
}

.heading-text h4 {
    font-size: 34px;
    margin-bottom: 30px;
    letter-spacing: -.7px;
    line-height: 40px;
}

.heading-text.heading-line h4:before {
    content: '';
    position: absolute;
    width: 100%;
    height: 15px;
    bottom: 5px;
    background-color: #fcf8e3;
    z-index: -1
}
<div class="heading-text heading-line">
  <h4>
    My super loooong title
  </h4>
</div>

<div class="heading-text heading-line">
  <h4>
    My short title
  </h4>
</div>

The issue I’m facing is the yellow bar is not fitting the text width.

Is there a way it can be adjust automatically ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks.

>Solution :

You could make the h4 not take the whole screen, by using display:inline-block;

.heading-text>* {
  position: relative;
  display:inline-block;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading