Mark Greenwood Team : Web Development Tags : Web Development CSS

CSS3 flexible width, fixed padding/margins

Mark Greenwood Team : Web Development Tags : Web Development CSS

Perhaps one of the most underestimated (and little known) abilities in CSS3 is the "calc()" function.

It's simple and yet can save so many headaches!

Ever wanted to set the width of something including the padding? With dynamic, responsive, fluid web pages, it is more and more of a problem. No more nested divs with padding and/or margins on the outers and inners, no more javascript onload!

With calc() it's now possible to achieve without nesting.

Whaaat?

An element that is 100% wide, but with a margin of 10px -> .classname { width:calc(100% - 10px); margin:0 10px; }

As simple as that, now if it was only that simple to get ALL the browsers to support it.

Get your act together Android and Opera (Mini).