| title | CSS |
|---|---|
| layout | default |
| parent | Web Development |
| nav_order | 2 |
| description | Tutorial CSS |
CSS (Cascading Style Sheets) is a powerful tool that lets you style and lay out your web pages effectively. Whether you're creating your first website or improving an existing one, understanding CSS is essential.
CSS (Cascading Style Sheets) is a stylesheet language that controls the appearance of HTML elements on a web page. It allows you to change colors, fonts, layouts, and more, making your web page visually appealing and user-friendly.
There are three main ways to apply CSS to your HTML document:
Add CSS directly to an HTML element using the style attribute.
<p style="color: blue;">This text is blue.</p>Use the <style> tag within the <head> section of your HTML document.
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: red;
}
</style>
</head>
<body>
<p>This text is red.</p>
</body>
</html>Link an external CSS file using the <link> tag.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<p>This text is styled from an external file.</p>
</body>
</html>CSS selectors are used to "select" HTML elements to style them.
Examples:
- Element selector:
p { color: green; } - Class selector:
.className { font-size: 16px; } - ID selector:
#idName { margin: 10px; }
Set text color and background styles.
body {
background-color: lightgray;
color: darkblue;
}Customize font style, size, and alignment.
h1 {
font-family: Arial, sans-serif;
text-align: center;
}Define margins, borders, padding, and content.
div {
margin: 20px;
padding: 10px;
border: 1px solid black;
}Adapt styles to different screen sizes.
@media (max-width: 600px) {
body {
background-color: yellow;
}
}Reuse values throughout your stylesheet.
:root {
--main-color: teal;
}
h1 {
color: var(--main-color);
}CSS is an essential part of modern web development. By mastering its basics and advanced features, you can create visually stunning and responsive websites. Keep experimenting with different properties and layouts to find what works best for your projects.
Happy coding!