CSS Complete Reference With Examples
CSS Complete Reference With Examples
CSS Introduction
CSS = Cascading Style Sheets. It defines the visual presentation of HTML - colors, fonts, layout.
/* Example */
body {
background-color: lightblue;
}
Selectors
CSS Selectors let you target elements. Includes: type, class, ID, combinators, pseudo-classes/elements.
/* Example */
#header {
background: black;
}
.article p {
font-style: italic;
}
a:hover {
color: green;
}
Box Model
Every element is a box: content + padding + border + margin.
/* Example */
div {
width: 200px;
padding: 10px;
border: 1px solid black;
margin: 20px;
}
text-align: center;
}
Layout
Control layout using display, float, position, z-index, overflow.
/* Example */
.container {
display: inline-block;
position: relative;
overflow: hidden;
}
Responsive Design
Media queries help your site adapt to screen sizes.
/* Example */
@media (max-width: 600px) {
body {
background-color: lightgrey;
}
}
Best Practices
Comprehensive CSS Reference with Examples
Use external CSS, write modular styles, comment sections, avoid repetition.
/* Example */
/* Primary button style */
.btn-primary {
background-color: blue;
color: white;
}