Home > Net >  Limit the bottom bar to the text and not the window width
Limit the bottom bar to the text and not the window width

Time:09-19

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 >
  <h4>
    My super loooong title
  </h4>
</div>

<div >
  <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 ?

Thanks.

CodePudding user response:

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

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

CodePudding user response:

Try this:

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

.short-text {
    display: inline-block;
}

.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 >
  <h4>
    My super loooong title
  </h4>
</div>

<div >
  <h4 >
    My short title
  </h4>
</div>

  •  Tags:  
  • css
  • Related