HTML5 & CSS3 Tutorial: Basic Web Layout With divs, id selectors, unordered lists, and floats

Courtesy Note: If you found this tutorial useful, please take a few moments to comment below!

The following notable HTML5/CSS3 topics will be covered in this tutorial:

1. New HTML5 Tags (header, nav, footer)
2. ‘id’ selectors
3. Unordered lists (‘ul’ HTML tag)
4. ‘float’ and ‘clear’ CSS3 properties


For those of you who don’t know, I’ve been working on a huge website project for the past few weeks and in doing so, I’ve familiarized myself and learned a whole lot about HTML5 and CSS3, and through my struggles of coding certain features, I had the inspiration of posting basic coding tutorials of how to perform certain tasks and do certain designs in HTML and CSS. The first tutorial I will be providing on this blog is making a basic web layout. This will also be posted in the “Code” section.

This will be a very basic tutorial of how to make a basic layout for a webpage using divs, unordered lists, and floats. I will be providing a screenshot of what the web layout will look like, as well as the code in html and css that designs that layout. Comments will be provided in each code snippet for html and css.

Objectives:

After studying the code and comments, you should be a little basic familiarity with how id selectors work and that they specify which styles the html code will be using from the css code, a little familiarity of why we had to use the float properties, what an unordered list looks like (in the code and visually), how the “clear” property works for floats, and how to make a really basic web layout.

Questions? Please leave a comment!

Desired Web Layout (with colors):

layout

HTML Code:

 

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="layout.css" />
    </head>
    <body>
        <div id="wrapper">
            <header> 
                Header
                <br />
                Header
                <br />
                Header
                <br />
                Header
                <br />
            </header>
            <nav>
                Navigation links go here.

                <ul>
                    <li>
                        <a href="#">Home</a>
                    </li>
                    <li>
                        <a href="#">Contact</a>
                    </li>
                    <li>
                        <a href="#">About</a>
                    </li>
                    <li>
                        <a href="#">Link #4</a>
                    </li>
                    <li>
                        <a href="#">Link #5</a>
                    </li>
                    <li>
                        <a href="#">Link #6</a>
                    </li>
                    <li>
                        <a href="#">Link #7</a>
                    </li>
                    <li>
                        <a href="#">Link #8</a>
                    </li>
                </ul>
            </nav>
            <div id="content">
                <p>Content goes here.</p>
            </div>
            <footer> 
                Footer
                <br />
                Footer
                <br />
                Footer
                <br />
                Footer
                <br />
            </footer>
        </div> <!-- Wrapper -->
    </body>
</html>

CSS Code:

Note: id selectors are always required to have the hashtag (#) before the name of the element in the css code.

 

body {
  background-color: yellow;
}

#wrapper {
  width: 80%;
  border-style: solid;
  border-color: black;
  border-width: medium;
  background-color: purple;
  margin-left: auto;
  margin-right: auto;
}

header {
  width: 100%;
  background-color: red;
}

nav {
  width: 30%;
  background-color: white;
  float: left;
  height: 400px;
}

#content {
  width: 70%;
  background-color: blue;
  float: right;
  height: 400px;
}

footer {
  clear: both;
  width: 100%;
  background-color: gray;
}

P.S:

You’re probably a motivated web developer who wants to freelance, blog, and/or be the best developer you can be. I feel many developers suffer from lack of clarity on their career/life, and poor time management and productivity practices. Without clarity and without the commitment to maximize your time, you don’t give yourself the ability to even work on your website projects and hone your coding skills with maximum efficiency.

To be the best coder, blogger, or freelancer you can be, it helps to master the non-technical aspects of entrepreneurship and personal growth. To begin building a solid foundation, I highly recommend that you consider getting my mentor’s free entrepreneurship book and training right now, where he shares his top 30+ tips that he followed in order to become a multi-million dollar entrepreneur in his 20s. I’ve read it, and as a blogger and web developer, it’s made a huge difference in my career outlook and my productivity! In addition, you may also find his productivity and time management master class useful to sign up for!

Remember that the book is free, so be sure to get it here now because I’m not sure if he’s planning to remove the book off the website! Obviously you have the choice, but I truly believe that you will learn some valuable lessons from it, like I have as a fellow blogger and developer. Please let me know if you have any questions, and I’d love to hear what you learn from the book!

teb-fb