CSS Basics
Learn the fundamentals of CSS styling
CSS Basics
CSS (Cascading Style Sheets) is used to style and layout web pages.
Selectors
/* Element selector */
h1 {
color: blue;
}
/* Class selector */
.highlight {
background-color: yellow;
}
/* ID selector */
#header {
font-size: 24px;
}
/* Attribute selector */
input[type="text"] {
border: 1px solid #ccc;
}
Box Model
.box {
width: 200px;
height: 100px;
padding: 20px;
border: 2px solid black;
margin: 10px;
}
Flexbox
.container {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
}
.item {
flex: 1;
}
Grid
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
Responsive Design
/* Mobile first */
.container {
width: 100%;
}
/* Tablet */
@media (min-width: 768px) {
.container {
width: 750px;
}
}
/* Desktop */
@media (min-width: 1024px) {
.container {
width: 1000px;
}
}
CSS is essential for creating beautiful and responsive web interfaces!