All the credits must go to Heydon Pickering & his article: http://www.heydonworks.com/article/tetris-the-power-of-css
A Pen by Yoel Cieno on CodePen.
All the credits must go to Heydon Pickering & his article: http://www.heydonworks.com/article/tetris-the-power-of-css
A Pen by Yoel Cieno on CodePen.
<main> | |
<section> | |
<h2>orphans</h2> | |
<p>adjusting the width of the last item in an incomplete grid with pure css</p> | |
</section> | |
<section> | |
<figure> | |
<img src='http://www.heydonworks.com/images/portrait.jpg' alt='Heydon Pickering' /> | |
<figcaption><a href='http://www.heydonworks.com/about'>Heydon Pickering</a></figcaption> | |
</figure> | |
</section> | |
<section> | |
<h2>what</h2> | |
<p>add or delete <section>´s and look at what happend with the widht of the last if it is the 3n+1 or 3n+2</p> | |
</section> | |
<section> | |
<h2>credits</h2> | |
<p>All the credits must go to <strong>Heydon Pickering</strong> & his article:<br/> <a href='http://www.heydonworks.com/article/tetris-the-power-of-css'>Tetris & The Power Of CSS</a> in his blog <strong>heydonworks</strong></p></section> | |
<section></section> | |
<section></section> | |
<section> | |
<p>If this section is the last, its width will be the 100% of its parent,</p> | |
</section> | |
<section> | |
<h2>the magic CSS </h2> | |
<pre> | |
section:nth-child(3n + 1):last-child { | |
width: 100%; | |
margin-right: 0; | |
} | |
section:nth-child(3n+2):last-child { | |
width: 65%; | |
margin-right: 0; | |
} | |
</pre> | |
</section> | |
</main> |
@import url(http://fonts.googleapis.com/css?family=Roboto:400,300,100); | |
@import url(http://weloveiconfonts.com/api/?family=entypo); | |
*, *:after, *:before { | |
box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
} | |
* {margin:0;padding:0;border: 0 none;position: relative;} | |
[class*="entypo-"]:before {font-family: 'entypo', sans-serif; display: inline-block; margin-right: 1rem;} | |
html { | |
background: url(http://farm9.staticflickr.com/8204/8237429748_216c68cda0_b.jpg) no-repeat 50% top fixed; | |
background-size: cover; | |
position: relative; | |
width: 100%; | |
height: 100%; | |
font-family: roboto; | |
font-size: 1.2rem; | |
font-weight: 300; | |
} | |
body { | |
width: 100%; | |
min-height: 100%; | |
background: inherit; | |
} | |
main { | |
margin: 5vw 5vw 0 5vw; | |
} | |
main:after { | |
content:''; | |
display: block; | |
clear: both; | |
height: 0; | |
} | |
section { | |
background: rgba(255,255,255,.8); | |
float: left; | |
width: 30%; | |
height: 35vw; | |
margin: 0 5% 5vw 0; | |
text-align: left; | |
box-shadow: 0 0 4px rgba(0,0,0,.4); | |
border-radius: .5vw; | |
overflow: hidden; | |
} | |
section:nth-child(3n) { | |
margin-right: 0; | |
} | |
section:nth-child(3n+1):last-child { | |
width: 100%; | |
margin-right: 0; | |
} | |
section:nth-child(3n+2):last-child { | |
width: 65%; | |
margin-right: 0; | |
} | |
h2 { | |
background: #94A392; | |
font-weight: 200; | |
font-size: 4.5vw; | |
line-height: 8vw; | |
text-align: center; | |
color: #fff; | |
border-radius: .5vw .5vw 0 0; | |
margin-bottom: 1rem; | |
z-index: 1; | |
} | |
p {padding: 0 1rem; | |
text-align: justify; | |
color: #94A392; | |
} | |
a { | |
color: #B86771; | |
text-decoration: none; | |
} | |
figure {position: static;} | |
figure img { | |
display: block; | |
width: 100%; | |
height: 100%; | |
border-radius: 50%; | |
border: 12px double #94A392; | |
} | |
figcaption, figcaption a { | |
position: absolute; | |
bottom: 0;left:0; right:0; | |
text-align: center; | |
line-height: 7vw; | |
background: #B86771; | |
color: #fff; | |
border-radius: 0 0 .5vw .5vw; | |
} |