I'm tring to write a css that for all string that I can put on increase these strings about 3px. I don't know how can I do this, I think something like this:
.increaseSize {
getSize()+3px;
}
Anyone can help me?
It is related to the font size of the parent container. One em (1em) is equal to the current font size. So for example, if the parent element has the font size of 16px than 1em is equal to 16px, 2em is equal to 32px, and so on. Making your design responsive becomes much easier if you use em units instead of px.
I would seek a different and much simpler approach.
p.myText {
font-size: 16px;
}
.increaseSize {
font-size: 1.5em
}
<p class="myText">This is some standard text and <span class="increaseSize">this is a bigger font size text</span></p>
This would make any .increaseSize element font size 50% bigger than its parent.
You can use calc() but maybe browser compatibility is a problem. This is a safer solution.
Does this help you?
You can use it like the following example:
div {
font-size: 1em;
}
span.increase {
font-size: calc(100% + 3px);
}
<div>
Hello <span class="increase">World</span>
</div>
With the %
unit you can get the actual font size of the element. Now you can use calc
(browser compatibility) to add the 3px
to the current font-size
.
You shouldn't calculate the
font-size
yourself for responsive web-design. You can / should use relative units likeem
,rem
or%
to achieve responsivefont-size
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With