I have tried to add an underline to a header of a website I have been developing. This underline works while hovering or active page, the problem is that I could not figure out to center the underline to the text if I change the width property
The website is https://www.faithful-farming.com/
And the code is the following:
elementor-item:after {
background-color: #E98B0D !important;
height: 5px;
content: "";
bottom: 0;
width: 100%;
left:0;
border-radius: 4px;
line-height: 2px;
}
So if I change the width: from 100% to 80%, it is not centered it and is set to the left due to left:0; I tried to use align center but I don’t know why is not working.
- Problem: if I change the size, it will not center it.
2
Answers
If you wish to center an element that is less than 100% width, you can not set the left margin to 0. Simply change the width to 80% and the left margin to auto or 10%.
Since your site is not set to public, I can only assume what exactly you want. Depending on the properties of the elementor-item itself, try the following:
If you now change the width of the pseudo element, the underline remains centered.
Note: .myElement must have a width set!
Here’s a fiddle: https://jsfiddle.net/qfo2xjrh/