Open In App

CSS Website Layout

Last Updated : 04 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

CSS website layout divides a webpage into multiple sections like header, navigation bar, content area, and footer, making it easier to organize content and build the site.

Structure of Website Layout

1. Header Section

The header is the top section of a webpage, typically containing the website’s name or logo.

html
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <style>
        .header {
            background-color: green;
            padding: 15px;
            text-align: center;
        }
        .header h2 {
            color: white;
            margin: 0;
        }
    </style>

<!--Driver Code Starts{-->
</head>
<body>
    <div class="header">
        <h2>GeeksforGeeks</h2>
    </div>
</body>
</html>
<!--Driver Code Ends }-->

In this example:

  • The <div class=”header”> element defines the header section of the webpage.
  • The .header CSS class styles the header with a green background, 15 pixels of padding, and centers the text.

2. Navigation Menu

The navigation menu is used to create a set of links for easy website navigation.

html
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <style>
        .nav_menu {
            overflow: hidden;
            background-color: #333;
        }
        .nav_menu a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }
        .nav_menu a:hover {
            background-color: white;
            color: green;
        }
    </style>

<!--Driver Code Starts{-->
</head>
<body>
    <div class="nav_menu">
        <a href="#">Algo</a>
        <a href="#">DS</a>
        <a href="#">Language</a>
    </div>
</body>
</html>

<!--Driver Code Ends }-->

In this example:

  • The .nav_menu class defines the style of the navigation menu with a dark background and ensures the links are aligned horizontally.
  • The a tag inside .nav_menu defines each link’s style, including white text and padding for spacing

3. Content Section 

The content section is used to add content to the page, and you can adjust it according to the screen size.

html
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <style>
        .columnA,
        .columnB,
        .columnC {
            text-align: center;
            color: green;
        }
    </style>

<!--Driver Code Starts{-->
</head>
<body>
    <div class="nav_menu">
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Contact</a>
    </div>

    <div class="columnA">Content for Column A</div>
    <div class="columnB">Content for Column B</div>
    <div class="columnC">Content for Column C</div>
</body>
</html>
<!--Driver Code Ends }-->

In this example:

  • The HTML structure defines three content sections, each inside a <div>, which can be further styled or adjusted as needed for responsive layouts.
  •  The .columnA, .columnB, and .columnC classes style the content areas, aligning the text to the center and coloring it green.

4. Footer Section

The footer section is placed at the bottom of the webpage and typically contains information like contact details, copyright, or about us. 

html
<!--Driver Code Starts{-->
<html>
<head>
<!--Driver Code Ends }-->

    <style>
        .footer {
            background-color: green;
            padding: 15px;
            text-align: center;
        }
    </style>

<!--Driver Code Starts{-->
</head>
<body>
    <center style="font-size:200%; margin-bottom: 300px;">Upper section</center>
    <div class="footer">
        <a href="#">About</a><br>
        <a href="#">Career</a><br>
        <a href="#">Contact Us</a>
    </div>
</body>
</html>
<!--Driver Code Ends }-->


In this example:

  • The .footer class defines the footer section, giving it a green background, padding, and centering the text.
  • Inside the footer, there are links for “About,” “Career,” and “Contact Us,” which provide quick access to those sections.

Important Points to Remember

  • The header section contains a website logo, a search bar, and user profile information.
  • The navigation menu includes links to various categories of articles available.
  • The content section is divided into three parts (columns), with left and right sidebars containing links to other articles and advertisements. The main content section holds the current article.
  • The footer at the bottom contains the address, links, contacts, etc.


Next Article

Similar Reads