Have a question?
Message sent Close
View Categories

CSS Website Layout

8 min read

Website Layout #

A website is often divided into headers, menus, content and a footer:

Layout Example
Header
Navigation Menu
Content
Main Content
Content

There are tons of different layout designs to choose from. However, the structure above, is one of the most common, and we will take a closer look at it in this tutorial.


  #

Header #

A header is usually located at the top of the website (or right below a top navigation menu). It often contains a logo or the website name:

.header { background-color: #F1F1F1; text-align: center; padding: 20px; }

Result:

CSS Website Layout

Header #

Navigation Bar #

A navigation bar contains a list of links to help visitors navigating through your website:

/* The navbar container */ .topnav { overflow: hidden; background-color: #333; } /* Navbar links */ .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; } /* Links - change color on hover */ .topnav a:hover { background-color: #ddd; color: black; }
CSS Website Layout

Result: #

Content #

The layout in this section, often depends on the target users. The most common layout is one (or combining them) of the following:

  • 1-column (often used for mobile browsers)
  • 2-column (often used for tablets and laptops)
  • 3-column layout (only used for desktops)

1-column:

 

2-column:

 

3-column:

We will create a 3-column layout, and change it to a 1-column layout on smaller screens:

/* Create three equal columns that floats next to each other */ .column { float: left; width: 33.33%; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; } /* Responsive layout - makes the three columns stack on top of each other instead of next to each other on smaller screens (600px wide or less) */ @media screen and (max-width: 600px) { .column { width: 100%; } }
CSS Website Layout

Result: #

Column #

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam orci in velit. Praesent scelerisque tortor sed accumsan convallis.

Column #

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam orci in velit. Praesent scelerisque tortor sed accumsan convallis.

Column #

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam orci in velit. Praesent scelerisque tortor sed accumsan convallis.

Tip: To create a 2-column layout, change the width to 50%. To create a 4-column layout, use 25%, etc.

Tip: Do you wonder how the @media rule works? Read more about it in our CSS Media Queries chapter.

Tip: A more modern way of creating column layouts, is to use CSS Flexbox. However, it is not supported in Internet Explorer 10 and earlier versions. If you require IE6-10 support, use floats (as shown above).

To learn more about the Flexible Box Layout Module, read our CSS Flexbox chapter.


  #

Unequal Columns #

The main content is the biggest and the most important part of your site.

It is common with unequal column widths, so that most of the space is reserved for the main content. The side content (if any) is often used as an alternative navigation or to specify information relevant to the main content. Change the widths as you like, only remember that it should add up to 100% in total:

.column { float: left; } /* Left and right column */ .column.side { width: 25%; } /* Middle column */ .column.middle { width: 50%; } /* Responsive layout - makes the three columns stack on top of each other instead of next to each other */ @media screen and (max-width: 600px) { .column.side, .column.middle { width: 100%; } }
CSS Website Layout

Result: #

Side #

Lorem ipsum dolor sit amet, consectetur adipiscing elit..

Main Content #

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam orci in velit. Praesent scelerisque tortor sed accumsan convallis.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam orci in velit. Praesent scelerisque tortor sed accumsan convallis.

Side #

Lorem ipsum dolor sit amet, consectetur adipiscing elit..

Footer #

The footer is placed at the bottom of your page. It often contains information like copyright and contact info:

.footer { background-color: #F1F1F1; text-align: center; padding: 10px; }
CSS Website Layout

Result: #

Responsive Website Layout #

By using some of the CSS code above, we have created a responsive website layout, which varies between two columns and full-width columns depending on screen width:

My Website #

Resize the browser window to see the effect.

TITLE HEADING #

Title description, Dec 7, 2017 #
Image

Some text..

Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.

TITLE HEADING #

Title description, Sep 2, 2017 #
Image

Some text..

Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.

About Me #

Image

Some text about me in culpa qui officia deserunt mollit anim..

Popular Post #

Image

Image

Image

Follow Me #

Some text..

Powered by BetterDocs

Leave a Reply