Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS style padding with em and px

Tags:

html

css

Is it possible to do padding with pixels and em? So for instance, can I add padding-left by 2em plus 1px? Something like this...

padding-left: 2em + 1px;
like image 716
Berry Blue Avatar asked Jun 14 '13 05:06

Berry Blue


People also ask

Can padding be in em?

The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion.

What is the correct order of CSS values for padding 10px 20px 30px 40px?

padding: 10px 20px 30px 40px; top padding is 10px, right padding is 20px, bottom padding is 30px, left padding is 40px.

Should I use em or REM for padding?

Use EM where you have to make more scaling than the root font size. And use REM where you need value according to the root there you can use REM units.


1 Answers

You are looking for the calc expression.

https://developer.mozilla.org/en-US/docs/Web/CSS/calc

for example:

padding: -webkit-calc(2em + 1px);
padding: calc(2em + 1px);

Be warned, (at the time of writing) this property is still considered experimental. You may want to check caniuse to see if this expression will work in all browsers you are developing for.

like image 137
uber5001 Avatar answered Oct 08 '22 17:10

uber5001