css - Calculate text height properly independently of font used to make a text element with a right arrow -
i'm trying create label has right arrow. looks this:
the code i'm using following (less):
@font-size: 14px; @padding-top: 4px; @arrow-bheight: @font-size; .label { position: relative; font-size: @font-size; font-weight: normal; font-style: italic; text-transform: uppercase; padding: @padding-top 8px; line-height: 1; color: #fff; background: #000; &:after { content: ""; width: 0; height: 0; border-top: @arrow-bheight solid transparent; border-bottom: @arrow-bheight solid transparent; border-left: @arrow-bheight solid #000; position: absolute; right: -@arrow-bheight; top:0; } }
my problem depending on font use, the arrow doesn't fit text font.
i've been trying set specific value line-height
, e.g. line-height: @font-size
, it's not working.
here's codepen of problem.
how can make right arrow have proper height regardless of font used?
there's no need define @padding-top
variable separately. instead use em
unit relative element's font-size
.
also should change display
type of labels inline-block
:
.label { display: inline-block; font-size: @font-size; /* has been set 14px */ padding: 0.5em 8px; /* computed value of 0.5em 14px/2 = 7px */ line-height: 1; /* other declarations... omitted due brevity */ }
Comments
Post a Comment