CSS (Cascading Style Sheets) is a language used to style the presentation of a webpage, including layout, colors, fonts, and responsiveness.
How CSS Works: CSS applies rules to HTML elements (such as <p>, <div>, etc.) based on selectors and modifies their properties.
CSS syntax consists of three main parts:
Example:
h1 {
color: red; /* Property: color, Value: red */
font-size: 24px; /* Property: font-size, Value: 24px */
}
Start by styling basic properties like:
color, font-size, font-family, text-align.width, height, margin, padding, border.Example:
body {
background-color: #f0f0f0;
color: #333;
font-family: Arial, sans-serif;
}
h1 {
font-size: 32px;
text-align: center;
}
CSS can be applied in three ways:
style attribute.<style> block in the <head> of the HTML document..css file linked to the HTML document.Example:
This is inline CSS.
The box model defines the structure of each element:
Example:
div {
width: 200px;
height: 100px;
padding: 10px;
border: 1px solid black;
margin: 20px;
}
Learn how to create layouts with:
Example (Flexbox):
.container {
display: flex;
justify-content: space-between;
}
Example (Grid):
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
Experiment with backgrounds, borders, and colors to enhance the visual appearance of your elements.
Example:
body {
background-color: #f9f9f9;
}
.box {
width: 150px;
height: 150px;
background-color: #4CAF50;
border-radius: 10px;
}
Use media queries to make your website responsive to different screen sizes.
Example (Media Query):
@media (max-width: 768px) {
body {
background-color: lightblue;
}
}
Add smooth transitions and animations to your elements.
Example (Transition):
button {
transition: background-color 0.3s ease;
}
button:hover {
background-color: #4CAF50;
}
Start building projects to apply what you've learned: