We'll use HTML5 and CSS3 to build a simple static homepage called Simply. Here's the final result
Understanding the Design
As you can see from the image, Simply is a full-width homepage design with 7 sections. We'll slice it into a series of manageable modules to make it easier to work with. Here's the structure
Setting Up the Folder Structure
First, create a folder for this project. It contains an HTML file, an images folder (with the image assets you need), and a CSS folder. Here's the directory structure
Download the image assets here: images. Here's the list of images
- hero.jpg - 2000 x 697 px
- features-icon-1.png - 100 x 100 px
- features-icon-2.png - 100 x 100 px
- features-icon-3.png - 100 x 100 px
- video-placeholder.jpg - 940 x 527 px
- article-image-1.jpg - 460 x 270 px
- article-image-2.jpg - 460 x 270 px
Setting Up the HTML File
Open index.html and enter the following code:
|
|
This code is the basic skeleton of every HTML file. It defines the document type (HTML5), the character encoding (UTF-8), and the page head. Besides this skeleton, we also use a conditional comment to add an "if it's IE9" script. This script lets HTML5 tags, such as
Breaking Down the Page
We've already broken the page into 7 sections. Now we'll break it down further into a basic structure that's easy to code, as shown below.
Notice that not every element is marked, only the most important parts. We'll add the rest with the content. Put this structure inside the HTML file's
|
|
Because the design is 960px wide, we need to add a wrapper inside each section, using a div container with a wrapper class.
Adding Content
In this part, we'll add content to the HTML file, including tags we didn't have before, such as paragraphs, headers, links, list items, and so on
Section 1: Header
The header includes a logo and a navigation bar. The logo uses an h1 tag and an inline color class, so we can set different colors in CSS later. The navigation bar is a simple unordered list, ul, with 4 li items inside a nav tag.
|
|
Section 2: Hero Image
A hero banner image with an h2 heading and a button link.
Section 3: Features
Section 3 has an unordered list. With CSS, these list items float left and display horizontally. To stop elements from floating, we need a div with a "clear" class. Later in the CSS, its property is "clear:both".
Section 4: Primary Content
This part is simple: use an tag to add a video cover image
|
|
Section 5: Secondary Content
Like the features section, we make the
Section 6: Call to Action
This one is also very simple: a heading, a paragraph, and a button link.
|
|
Section 7: Footer
The footer is split into two columns, "footer-info" and "footer-link," and the latter is divided into 3 columns using list items.
Next, include the CSS files we need. The first is a CSS reset, which you can download here: CSS Reset. Put it in the css folder and link it in the HTML.<link rel="stylesheet" type="text/css" href="css/reset.css">
Also link our custom CSS<link rel="stylesheet" type="text/css" href="css/home.css">Our logo font, "Crete," comes from Google Fonts, so we need to link it too.<link href='http://fonts.googleapis.com/css?family=Crete+Round' rel='stylesheet' type='text/css'>
Adding Styles
Global Styles
The body, headings, paragraphs, and links are global styles that apply to the whole file, so we define them first. The wrapper is 960px wide, minus 10px of padding on each side. Because we're using a CSS reset, some properties need to be redefined.
Section 1: Header
The H1 tag sets the logo font size, the color property sets the logo color, and the li items inside the ul float left.
Section 2: Hero Image
The #hero-image height is a bit smaller than the background image, leaving a few pixels at the top and bottom for small adjustments or a responsive layout later.
Section 3: Features
Every feature shares the #features ul li styles. But .feature-1, .feature-2 and .feature-3 each differ, with each one defining a different icon.
Section 4: Primary Content
heading 3 is underlined and centered, as already defined in the global styles.
|
|
Section 5: Secondary Content
The first-child selector applies a 20px margin only to the first article, and .overlay uses rgba to give it a slightly transparent white background.
|
|
Section 6: Call to Action
This uses the same custom <h3> style. It also defines the button and its hover state.
|
|
Section 7: Footer
We use floats to split the Footer into two columns, #footer-info and #footer-links, then use the same approach to split #footer-links into three horizontal unordered lists.
|
|
Conclusion
And that's it: we've built a site homepage with HTML5 and CSS3.
