Styling the Web Page
Now that we have created the basic structure of the web page using the <div>
tag, we can apply CSS styles to make the page look better.
- Open the
style.css
file in your text editor, or create a new file named style.css
and link it to the index.html
file using a <link>
tag inside the <head>
section.
<!doctype html>
<html>
<head>
<title>My Web Page</title>
<link rel="stylesheet" href="style.css" />
</head>
<body></body>
</html>
- In the
style.css
file, add the following styles to the different class names that we used earlier:
/* Header styles */
.header {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px;
}
/* Container styles */
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
/* Sidebar styles */
.sidebar {
width: 30%;
padding: 10px;
background-color: #f2f2f2;
}
/* Main Content styles */
.main-content {
width: 65%;
padding: 10px;
background-color: #fff;
}
/* Footer styles */
.footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px;
}
Previewing the Web Page
Now that we have created the web page structure and applied CSS styles using the <div>
tag, let's preview the web page in a web browser.
-
Save the index.html
and style.css
files.
-
Open the index.html
file in a web browser to see the web page.
You should see a web page with a header, sidebar, main content, and footer section, all nicely styled using CSS.