How does the padding work in responsive CSS square? -
i learning how develop responsive liquid css designs , came across technique, block display elements (eg. div) have % dimensions. in order display them, following css code used:
.class:before { content: ""; display: block; padding-top: 100%; }
my confusion comes padding property. far know, in css box model (css2), padding affects inner part of block element, not outer. in technique used, without it, element not visible. explain me in terms of box model, padding property here?
in case explanation confusing, attaching 2 links working examples:
http://www.mademyday.de/css-height-equals-width-with-pure-css.html
http://jsfiddle.net/josedvq/38tnx/
alexander.
css pseudo element ::before (:before)
or ::after (:after)
+ content
property, creates child element inside container.
and a percentage padding
value relative width
of container - w3c spec, padding-top:100%
+ display:block
creates square.
.square { width: 10%; background: blue; } .square:before { content: ""; display: block; padding-top: 100%; }
<div class="square"></div>
Comments
Post a Comment