As shown in this fiddle, I have a custom underline that uses transform: skew(-30deg) rotate(-2deg);
.
How can I replace the -2 with a formula that uses the width?
E.g. [width in pixels] * .004 - 2.4
I never know the width ahead of time because the quotes and fonts can change.
.underlined {
$lineColor: #4ffe25;
position: relative;
z-index: 2;
&::before {
background-color: $lineColor;
content: "";
position: absolute;
width: calc(99% + 0px);
height: 15%;
left: 0;
top: 95%;
z-index: -1;
transform: skew(-30deg) rotate(-2deg); /* How to use a formula for the `rotate` value? */
}
}
2
Answers
I don’t think there is a supported angle unit that takes dynamic radius into consideration. However, you could consider using
clip-path
instead. The use of length-percentage refers to the length and height of the element.You could play around with gradient background images as they ‘know’ about coming to/going from corners and don’t depend on your knowing the width in advance.
Here’s an example which alters depending on font size.