Continuing from where we left off in our previous post about HTML โ the structure of a web page, let's now move to the next crucial aspect of web development - CSS, or Cascading Style Sheets.
Remember the house analogy from our HTML post? If HTML is the framework of the house, CSS is the interior designer that makes it look beautiful. It controls the layout, color scheme, fonts, and other visual elements of the web page.
Without CSS, our web pages would look like plain documents - boring and unengaging. CSS adds the pizzazz that captures the users' attention and improves their experience.
Let's take the HTML code we used in the previous post:
<!DOCTYPE html>
<html>
<head>
<title>My First Website</title>
</head>
<body>
<h1>Welcome to my Website!</h1>
<p>This is a paragraph about me.</p>
<img src="myphoto.jpg" alt="A photo of me">
</body>
</html>
Here's how we can style it with CSS:
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
h1 {
color: #333333;
text-align: center;
}
p {
color: #666666;
font-size: 16px;
}
๐ Here's a quick breakdown:
1. body
: This selector targets the <body>
tag in our HTML. We're setting the background color of the entire page to light blue.
2. h1
: We're styling the heading by changing its color to navy and centering the text.
3. p
: For the paragraph, we're changing the font to Arial and setting the font size to 18px.
4. img
: For the image, we're setting a specific width, maintaining its aspect ratio with 'auto' height, and making the image circular with a border-radius
of 50%.
This CSS can be added in a separate .css
file and linked to the HTML using a <link>
tag, or it can be added directly into the HTML within <style>
tags in the <head>
.
Imagine if our webpage was a house. Without CSS, it would be a bare, concrete structure. With CSS, we add color to the walls, position our furniture, and hang our art โ making it a comfortable, appealing space to live in.
That's it for this quick introduction to CSS. In the next post, we'll introduce JavaScript, the tool that makes our website interactive โ like installing electricity to power our appliances!
Remember, building a beautiful website is like crafting a masterpiece. Keep painting with CSS and soon you'll have a site that's not just functional, but also visually stunning. ๐๐ฉโ๐ป