html - CSS padding while retaining the defined size? -



html - CSS padding while retaining the defined size? -

according standard, adding padding html element in css grow element amount defined. example:

.elem { width: 100px; height: 100px; padding: 20px; }

will add together 20 pixels .elem's sides, causing actual width , height 140px total.

since pretty impractical in web design (having calculate , maintain track of resulting sizes), wondering if somehow possible reverse instead. set padding, , inner text area shrinks instead. element stays @ 100*100px, has padding of 20px within it, , don't have worry messing design while experimenting padding.

is possible? perhaps through language compiles css (haven't looked much)? , perhaps more minor question: why work way in first place?

use box-sizing:

elemselector { -moz-box-sizing: border-box; -ms-box-sizing: border-box; -o-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }

this value property declares declared size of element include border , padding.

references:

box-sizing at: 'css basic user interface module level 3 (css ui)'. box-sizing @ mdn.

html css padding

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -