🎉 Welcome to PyVerse! Start Learning Today

PYTHONDATA SCIENCE

Intro to CSS3

Welcome to the World of CSS3!

Hey there, aspiring web developers! Today, we are diving into the fabulous world of CSS3, which stands for Cascading Style Sheets! If HTML is like the bones of a web page, then CSS is the skin and clothes that make it look good!

Imagine your favorite website. Why do you think it's visually appealing? That's right! CSS is responsible for that. It defines how HTML elements should appear on the screen. Let's explore how CSS3 takes web design to the next level!

 What is CSS?

CSS is a style sheet language used to describe the presentation of a document written in HTML or XML. Think of it as a set of instructions telling your browser how to style the text, images, and layout of your website.

Why Use CSS?

  • Separation of content and style: You can keep your HTML content separate from its design.
  • Easy to maintain: If you want to change a style, you can do it in one place, and it can apply to multiple pages!
  • More control: CSS gives you control over the layout, colors, fonts, and pretty much everything you see on a webpage.

 CSS3 Features

CSS3 comes packed with amazing features that make web design even more fantastic! Here are some cool things you can do with CSS3:

  1. Selectors: You can select different HTML elements to apply styles.
  2. Colors: You can use named colors, hex codes, and even RGBA for transparency!
  3. Fonts: Use web fonts and change font sizes, families, and styles.
  4. Box Model: Everything in a webpage is a box! You can control margins, padding, borders, and dimensions.
  5. Transitions and Animations: Make elements move or change styles over time!

 Example of Basic CSS

Here's a simple example that shows how CSS can style an HTML page.

Let's say we have the following HTML:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="styles.css"> <title>My First Webpage</title> </head> <body> <h1>Welcome to My Webpage!</h1> <p>This is my first attempt at using CSS!</p> </body> </html>

Now, let's create a file called styles.css to style our webpage.

body { background-color: lightblue; font-family: Arial, sans-serif; text-align: center; } h1 { color: darkblue; font-size: 3em; } p { color: darkgreen; font-size: 1.5em; }

Breakdown of the CSS Code:

  • body sets the background color to light blue and centers the text.
  • h1 changes the heading color to dark blue and makes it really big!
  • p makes the paragraph text dark green and a bit larger.

💻 Practical Exercise: Create Your Own Styled Webpage!

Now it's time to get your hands dirty and have some fun! Here's a mini project for you:

Project: My Personal Greeting Page

1. Create an HTML file called greeting.html:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="greeting.css"> <title>My Personal Greeting</title> </head> <body> <h1>Welcome to My World!</h1> <p>I'm learning CSS to make awesome webpages!</p> <button>Click Me!</button> </body> </html>

2. Create a CSS file called greeting.css and style your page! Feel free to use styles you learned or try new ones. Here's a starting point:

body { background-color: #f0f8ff; /* AliceBlue */ font-family: 'Tahoma', sans-serif; text-align: center; } h1 { color: #4169e1; /* RoyalBlue */ font-size: 3em; text-shadow: 2px 2px #ffffff; /* white shadow effect */ } p { color: #ff6347; /* Tomato */ font-size: 1.5em; } button { background-color: #008cba; /* Blue */ color: white; font-size: 1em; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #005f75; /* Darker Blue */ }

3. Preview your greeting page in a web browser and make adjustments as needed. Experiment with colors, fonts, and layouts!

Recap

In this lesson, we learned what CSS3 is and how it plays a key role in web design. We explored some basic features, wrote our first CSS code, and even created our own personal greeting page!

Remember, CSS is powerful and creative. The best part is, the more you practice, the better you'll get!

Next time, we'll dive deeper into CSS positioning and layouts, but for now, keep experimenting and have fun styling your web pages! 

Happy coding! 

Loading quizzes...