CSS3 of the Holy Grail Layout Calc and Flex

Source: Internet
Author: User

There are many ways to achieve the Grail layout.

Mostly with the help of padding, margin, float and the like, of course, this is the traditional way of implementation. More reference ways to the Holy Grail layout summary.

This is said to be implemented with CSS3 Cal and Flex, because CSS is limited, there are errors or mistakes, please note.

CSS3 Cal Support situation, overall 93%.

Support for flex layouts, overall 97%

To increase the complexity of

1. Spacing between blocks

2. With border

3. The Box-sizing:content-box is used

See Calc's implementation first

<! DOCTYPE html>"en">"UTF-8"> <meta name="Viewport"Content="Width=device-width, initial-scale=1"> <style>html, body {height: -%; Width: -%; Margin:0; padding:0; Box-sizing:border-box}. Header {background:red;        height:100px;            }. footer {height:100px;            Position:absolute; Bottom:0; Width: -%; Box-sizing:border-box; Background-color:palevioletred}. Header,. Footer,. Left,. Content,. Right {            border:10px solid black; Box-sizing:border-box}. Left {margin:20px0;            Background:green;        width:100px;            }. Content {margin:20px 20px; Background-Color:silver; Width:calc ( -% -240px); Width:-webkit-calc ( -% -240px); Width:-moz-cal ( -%-240px); }. Right {margin:20px0; Background-Color:yellow;        width:100px; }. Left,. Content,. Right {float: Left; Height:calc ( -% -240px); Height:-webkit-calc ( -% -240px); Height:-moz-cal ( -%-240px); }    </style>class="Header">header</div> <divclass=" Left">left</div> <divclass="content">content</div> <divclass=" Right">right</div> <divclass="Footer">footer</div></body>

Effect

Now see how flex is implemented

<! DOCTYPE html>"en">"UTF-8"> <meta name="Viewport"Content="Width=device-width, initial-scale=1"> <style>html, body {height: -%; Width: -%; Margin:0; padding:0} body {Display:flex; Flex-Direction:column;            }. header {height:100px;        background:red;            } #container {Display:flex; Flex:1 1Auto; margin:20px0; }. Left {background-Color:green; }. Right {background-Color:yellow; }. Content {flex:1 1Auto; Background-Color:silver; Margin:020px;                       }. footer {height:100px; Width: -%; Background-color:palevioletred}. Left,. Right {flex:0 0100px; }. Left,. Right,. Content,. Header,. footer {Box-sizing:border-box;        border:10px solid black; }    </style>class="Header">header</div> <div id='Container'> <divclass=" Left">left</div> <divclass="content">content</div> <divclass=" Right">right</div> </div> <divclass="Footer">footer</div></body>

Effect:

The effect is the same, all just pull the extension to fill automatically.

But when you remove the Box-sizing:border-box, you will find that Calc has broken down, but flex is still not chaotic.

That's why I love flex. There are so complex to calculate, sincere class, support is not high flex.

Am I still too young?

Reference:

Holy Grail Layout Summary

CSS3 of the Holy Grail Layout Calc and Flex

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.