HTML
CSS
JavaScript
jQuery
PHP
SQL
WordPress
HTML Tutorials

Overview

There are many ways to do HTML layouts that are both semantic and able to accommodate varying screen sizes. For instance, for beginner’s the CSS Float and Flexbox layouts are simple to setup and easy to work with.

CSS Float Layout

It is common to do entire web layouts using the CSS float and clear properties. It’s easy to learn and works well for the most part.

Disadvantages: Floating elements are tied to the document flow, which can make things difficult to work with when accommodating a wide variety of screen sizes.

				
					<!DOCTYPE HTML>
<html lang="en-US">

<head>

    <meta charset="UTF-8">
    <meta name="description" content="Free Web Tutorials">
    <meta name="keywords" content="HTML, CSS, JavaScript, PHP, SQL">
    <meta name="author" content="1SMARTchicken">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>CSS Float Layout</title>


    <!-- styles -->
    <style>
        * {
            box-sizing: border-box;
        }
        header {
            background-color: #2d2d2d;
            padding: 30px;
            text-align: center;
            font-size: 36px;
            color: #ffffff;
        }
        nav {
            float: left;
            width: 25%;
            background: #bababa;
            padding: 20px;
            min-height: 300px;
        }
        nav ul {
            list-style-type: none;
            padding: 0;
        }
        article {
            float: left;
            padding: 20px;
            width: 75%;
            background-color: #f1f1f1;
            min-height: 300px;
        }
        section::after {
            content: "";
            display: table;
            clear: both;
        }
        footer {
            background-color: #2d2d2d;
            padding: 10px;
            text-align: center;
            color: #ffffff;
        }
        @media (max-width: 600px) {
            nav,
            article {
                width: 100%;
                height: auto;
                min-height: 0;
            }
        }
    </style>

</head>


<body>

    <header>
        <h1>CSS Float Layout</h1>
    </header>

    <section>
        <nav>
            <ul>
                <li><a href="#">Lamborghini</a></li>
                <li><a href="#">Ferrari</a></li>
                <li><a href="#">Maserati</a></li>
            </ul>
        </nav>

        <article>
            <h2>Exotic Sports Cars</h2>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit sapiente eveniet cupiditate non
                repudiandae in accusantium, possimus blanditiis deserunt at. Velit quo veritatis ullam? Delectus nam
                ullam facere molestiae iste!</p>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit sapiente eveniet cupiditate non
                repudiandae in accusantium, possimus blanditiis deserunt at. Velit quo veritatis ullam? Delectus nam
                ullam facere molestiae iste!</p>
        </article>
    </section>

    <footer>
        <p>&copy; Copyright. All Rights Reserved.</p>
    </footer>

</body>

</html>
				
			

CSS Flexbox Layout

Flexbox is only slightly more difficult to understand and learn than CSS float. But when used correctly, it allows for flexible layouts that easily accommodate all screen sizes without the extra work CSS float requires.

Notice that the structure of the page is exactly the same, but the CSS changes slightly using the flex properties to do all the work.

				
					<!DOCTYPE HTML>
<html lang="en-US">

<head>

    <meta charset="UTF-8">
    <meta name="description" content="Free Web Tutorials">
    <meta name="keywords" content="HTML, CSS, JavaScript, PHP, SQL">
    <meta name="author" content="1SMARTchicken">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>CSS Flexbox Layout</title>


    <!-- styles -->
    <style>
        * {
            box-sizing: border-box;
        }
        header {
            background-color: #2d2d2d;
            padding: 30px;
            text-align: center;
            font-size: 36px;
            color: #ffffff;
        }
        section {
            display: flex;
        }
        nav {
            flex: 1;
            background: #bababa;
            padding: 20px;
        }
        nav ul {
            list-style-type: none;
            padding: 0;
        }
        article {
            flex: 3;
            padding: 20px;
            background-color: #f1f1f1;
        }
        footer {
            background-color: #2d2d2d;
            padding: 10px;
            text-align: center;
            color: #ffffff;
        }
        @media (max-width: 600px) {
            section {
                flex-direction: column;
            }
        }
    </style>

</head>


<body>

    <header>
        <h1>CSS Float Layout</h1>
    </header>

    <section>
        <nav>
            <ul>
                <li><a href="#">Lamborghini</a></li>
                <li><a href="#">Ferrari</a></li>
                <li><a href="#">Maserati</a></li>
            </ul>
        </nav>

        <article>
            <h2>Exotic Sports Cars</h2>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit sapiente eveniet cupiditate non
                repudiandae in accusantium, possimus blanditiis deserunt at. Velit quo veritatis ullam? Delectus nam
                ullam facere molestiae iste!</p>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit sapiente eveniet cupiditate non
                repudiandae in accusantium, possimus blanditiis deserunt at. Velit quo veritatis ullam? Delectus nam
                ullam facere molestiae iste!</p>
        </article>
    </section>

    <footer>
        <p>&copy; Copyright. All Rights Reserved.</p>
    </footer>

</body>

</html>
				
			

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

HTML
CSS
JavaScript
jQuery
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.