The implementation process of the Holy Grail Layout

Source: Internet
Author: User

The implementation process of the Holy Grail Layout

The holy cup layout and the dual-flying wing layout both require three columns of layout, the middle width is adaptive, and the width is fixed on both sides. The advantage of this is that the important thing is that the rendering can be prioritized before the document stream, the dual-flying wing layout is an improvement to the layout of the holy cup, which will be discussed in the next article.

Holy cup layout: Floating, negative margin, and relative positioning are used without adding additional labels.

DOM structure:

<div class="header">Header</div><div class="bd">    <div class="main">Main</div>    <div class="left">Left</div>    <div class="right">Right    </div></div><div class="footer">Footer</div>

Style:

    <style>        body{padding:0;margin:0}        .header,.footer{width:100%;  background: #666;height:30px;clear:both;}        .bd{            padding-left:150px;            padding-right:190px;        }        .left{            background: #E79F6D;            width:150px;            float:left;            margin-left:-100%;            position: relative;            left:-150px;        }        .main{            background: #D6D6D6;            width:100%;            float:left;        }        .right{            background: #77BBDD;            width:190px;            float:left;            margin-left:-190px;            position:relative;            right:-190px;        }    </style>

 

Style change process in the left, middle, and right

1. The middle part needs to change according to the browser width, so we need to use 100%. Here we set the left center to right to left, because the center 100%, the left layer and the right layer have no position at all.

       .left{            background: #E79F6D;            width:150px;            float:left;        }        .main{            background: #D6D6D6;            width:100%;            float:left;        }        .right{            background: #77BBDD;            width:190px;            float:left;        }

2. After negative margin150 is added to the left layer, it is found that the left layer has gone up, because the negative side has no position in the out window and can only be moved up.

 .left{            background: #E79F6D;            width:150px;            float:left;            margin-left:-150px;        }

3. in step 2, we can see that it can be reached to the leftmost as long as the window width is moved. Use the negative margin to locate the left and right columns.

        .left{            background: #E79F6D;            width:150px;            float:left;            margin-left:-100%;        }        .right{            background: #77BBDD;            width:190px;            float:left;            margin-left:-190px;        }

4. But the problem is that the middle is blocked by the left and right sides, so I have to add padding to the outer layer.

       .bd{            padding-left:150px;            padding-right:190px;        }

5. The left and right columns are indented, so the relative positioning method is used to separate the rows from the left and right columns to obtain the final result.

        .left{            background: #E79F6D;            width:150px;            float:left;            margin-left:-100%;            position: relative;            left:-150px;        }        .right{            background: #77BBDD;            width:190px;            float:left;            margin-left:-190px;            position:relative;            right:-190px;        }

Original

Related Article

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.