0

I'm designing a CSS template that will consist of four sections:-

  1. Header
  2. Side Navigation
  3. Main Content
  4. Footer

The Side navigation & main content will be rendered along side each other, (25%, 75%) width.

My question, is should these two sections be in another container, or should they sit on the page at the same level as the header & footer?

1
  • 1
    Normally no one could answer your question, because you do things in the wrong order! First you start with your HTML code and its requirements depend on your content and semantics (and in some cases also on the wanted presentation, e.g. if container elements are required). Then you write your CSS code to achieve the wanted presentation of your markup! And what if the viewport is not width enough for your "2-column layout"? Commented Apr 27, 2014 at 15:32

3 Answers 3

1

Depending on your requirements (which seem very simple right now). You can do both so I think you should minimize markup and set them at the same level as header and footer.

Here is an example of what you could do :

FIDDLE

<header></header>
<nav></nav>
<main></main>
<footer></footer>

CSS :

header, footer {
    height: 200px;
    background:green;
    clear:both;
}
nav, main {
    float:left;
    width:25%;
    height:500px;
    background:gold;
}
main {
    width:75%;
    background:red;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Side bar and navigation can be down this way within their own container which is on the same level as the header and footer.

HTML

<div class="container">
    <div class="sidebar">
    </div>
    <div class="main-content">
    </div>
</div>

CSS

.container {
    width:100%
}
.sidebar {
    float:left;
    width:25%
}
.main-content {
    float:left;
    width:75%;
}

OR they can both be on the same level as the header and footer, as below (but may have issues if one doesn't have as much content as the other, which can be fixed using clear:both):

HTML

<div class="sidebar">
</div>
<div class="main-content">
</div>

CSS

.sidebar {
    float:left;
    width:25%
}
.main-content {
    float:left;
    width:75%;
}

Comments

1

You should use the same level. What you're trying to achieve is possible through CSS and the sections should be simple and logical. Too much nesting makes for a mess and makes it harder to code correct CSS. Here's some sample HTML:

<html>
    <head>
        <title>My website</title>
        <!-- And the rest of the head stuff, including a link to your CSS -->
    </head>
    <body>
        <header>
            <h1>My website</h1>
            <nav id="headnav">
                <ul>
                    <li>Login</li>
                    <li>About</li>
                </ul>
            </nav>
        </header>
        <nav id="mainnav">
            <ul>
                <li>First page</li>
                <li>Second page</li>
                <li>Third page</li>
            </ul>
        </nav>
        <main>
            <h2>Main content</h2>
            <p>This is some main content text.</p>
        </main>
        <footer>
            <p>Copyright and cookies and bears, oh my...</p>
        </footer>
    </body>
</html>

Then you position the stuff where you want it by using CSS. Any superfluous tags should always be stripped away. Here's some CSS to go along with the HTML:

header {
    clear: both;
    width: 100%;
}

nav#mainnav {
    width: 25%;
    float: left;
}

main {
    width: 75%;
}

footer {
    clear: both;
    width: 100%;
}

2 Comments

Any special reason why not using HTML5 nowadays with the appropriate elements?
Not really, I suppose. Even IE has fairly good support from IE8 and up. It's a bad habit of mine that I'm working to get rid of. :-) I'll edit the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.