Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing Holy Grail and Double Wing Layouts with CSS

Tech 2

The Holy Grail layout refers to a classic webpage structure with a header, footer, and a central content area flanked by two sidebars, typically requiring the main content to be prioritized in the HTML source.

Implementation Using Float

<body>
    <div class="site-header">Site Header</div>
    <div class="content-wrapper">
        <div class="primary-content">Primary Content</div>
        <div class="sidebar-left">Left Sidebar</div>
        <div class="sidebar-right">Right Sidebar</div>
    </div>
    <div class="site-footer">Site Footer</div>
</body>
* {
    margin: 0;
    padding: 0;
}
.site-header,
.site-footer {
    height: 100px;
    background-color: #5f9ea0;
}
.site-footer {
    clear: both;
}
.content-wrapper {
    padding-left: 200px;
    padding-right: 200px;
    min-width: 200px;
}
.content-wrapper div {
    position: relative;
    float: left;
    height: 300px;
}
.primary-content {
    background-color: #faebd7;
    width: 100%;
}
.sidebar-left {
    width: 200px;
    margin-left: -100%;
    left: -200px;
    background-color: #a52a2a;
}
.sidebar-right {
    width: 200px;
    margin-left: -200px;
    left: 200px;
    background-color: #6495ed;
}

This approach releis on a combination of negative margins, relative positioning, and container padding to position the sidebars. The primary content block occupies the full width initially, and the sidebars are pulled into place using negative left margins and relative offsets.

Alternative Float Implementation

Another method involves placing the primary content element after the sidebars in the HTML. The sidebars are floated left and right respectively, allowing the primary content block to flow between them. Clearing the float on the footer remains necessary.

Double Wing Layout

<body>
    <div class="site-header">Site Header</div>
    <div class="content-wrapper">
        <div class="primary-content">
            <div class="content-inner">Primary Content</div>
        </div>
        <div class="sidebar-left">Left Sidebar</div>
        <div class="sidebar-right">Right Sidebar</div>
    </div>
    <div class="site-footer">Site Footer</div>
</body>
* {
    margin: 0;
    padding: 0;
}
.site-header,
.site-footer {
    height: 100px;
    background-color: #5f9ea0;
}
.site-footer {
    clear: both;
}
.content-wrapper {
    min-width: 200px;
}
.content-wrapper div {
    float: left;
    height: 300px;
}
.primary-content {
    background-color: #faebd7;
    width: 100%;
}
.sidebar-left {
    width: 200px;
    margin-left: -100%;
    background-color: #a52a2a;
}
.sidebar-right {
    width: 200px;
    margin-left: -200px;
    background-color: #6495ed;
}
.content-inner {
    padding-left: 200px;
    padding-right: 200px;
}

Key Distinction

The fundamental difference lies in how space is created for the sidebars:

  • In the Holy Grail layout, padding is applied to the outer container (.content-wrapper).
  • The Double Wing layout achieves this by aplying left and right padding to an inner wrapper (content-inner) nested with in the primary content block, effectively creating gutters for the floated sidebars.
Tags: CSSLayout

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.