I want the normal
line-height, plus 4px. I have tried
line-height: normal + 4px;
but that doesn't work.
(Note: I don't want approximations using percentages.)
The default line-height is about 110% to 120% for the majority of the browsers. The line-height property sets the leading of lines of a text. If the line-height value is greater than the font-size value of an element, the difference will be the leading of text.
line-height: 1.5 (without units) will mutiply the element's font size by 1.5 to compute the line height. line-height: 150% will take 150% of the element's computed font size to compute the line height, which is equivalent to multiply it by 1.5 .
It takes the font-size value and multiplies it by 1.2 . Let's calculate the height of one line with the following example. We just have to do the following calculation: 16 * 1.5 = 24px. So we now know that our text will have a minimum height of 24px.
Why not just take aways Chromes little focus glare?
use the css property outline: none;
http://jsfiddle.net/XF6fS/
You can't do any arithmetic in CSS. Libraries like LESSCSS allow you to do certain things, but you can't get properties of rendered elements.
You could use percentages to get an approximation, however you should probably set an explicit line-height
for the elements; this will be the same accross browsers.
Running this JSFiddle shows the following results:
20px
normal
normal
Set an explicit height; it's going to be much better compatible with all browsers.
There is no direct way to do it. As said, you cannot do any calculations in CSS
files. That's why we keep saying that CSS
is not complete, we have to make float
s to display our pages properly, which is nonsense when you think about it.
As you have created the css, you can add 4pt yourself. If you don't want to hard-code, you can use CSS frameworks or other languages that create CSS output. Frameworks are fine, but I do not recommend using other languages that create CSS output for you. This is fun, but you will not learn the language and since CSS
is a hard-to-understand language, you will stuck if you have any errors, misplacements on your page.
So, about your question, you can use javascript
to getComputedStyle
and add 4pt
and set the style of the element.
This is the javascript that gets the style:
function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}
var height = parseInt(getStyle("elementId", "line-height"));
var earlycss = document.getElementById("elementId").style.cssText
document.getElementById("elementId").style.cssText = earlycss + "\nline-height: " + (height + 4) + "px;";
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