nav ul {
list-style: none;
padding: 0;
}
nav a {
display: block;
padding: 10px;
text-decoration: none;
}
nav li {
display: inline-block;
}
nav a {
padding: 10px 20px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
}
.dropdown:hover .dropdown-content {
display: block;
}
.gallery {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.gallery img {
width: 200px;
height: 150px;
object-fit: cover;
}
A single image containing multiple icons is used as a sprite. The background-position property shifts the visible portion.
.icon-home {
width: 32px;
height: 32px;
background: url("sprites.png") 0 0;
}
.icon-settings {
background: url("sprites.png") -32px 0;
}
input[type="text"],
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background: #3b82f6;
color: #fff;
padding: 10px 20px;
border: none;
cursor: pointer;
}
button:hover {
background: #2563eb;
}
ol {
counter-reset: section;
}
li::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
px — absolute pixelsem — relative to parent font-sizerem — relative to root font-size% — relative to parent elementvw — 1% of viewport widthvh — 1% of viewport heightSpecificity determines which rule wins when multiple rules target the same element. Inline styles beat IDs, IDs beat classes, classes beat elements.
p { color: black; } /* specificity: 1 */
.text { color: blue; } /* specificity: 10 */
#intro { color: green; } /* specificity: 100 */
<p style="color: red;"> /* specificity: 1000 */
Build a horizontal navigation bar with a dropdown submenu. Style a contact form with labeled inputs, a textarea, and a styled submit button.