<p class="hero-text">
Content content content.
</p>
<p class="hero-text red">
More content.
</p>
.hero-text {
font-size: 25px;
}
.red {
color: red;
}
<button class="form-btn" id="submit">Submit</button>
#submit {
background-color: green;
}
.form-btn {
background-color: white;
border: 3px solid blue;
}
button {
padding: 10px 20px;
border: none;
background-color: blue;
}
When an element has conflicting styles added to it, CSS specificity determines which style is used.
It works like a point system. The highest score styling block is applied.
Selecting the element: 1 point
Selecting the class: 10 points
Selecting the id: 100 points
Inline Styling: 1000 points
<div class="example" id="test"></div>
#test {
height: 100px;
width: 100px;
background-color: cyan;
}
.example {
height: 100px;
width: 100px;
background-color: blanchedalmond
}
Specifies the display behavior of an element
block - Stacks vertically and takes full width available, unless otherwise specified. Can change height and width.
inline - allows horizontal stacking. Size is only what it needs for its content. Can't change height or width.
inline-block - allows horizontal stacking. Can change height and width.
div {
width: 100vw;
height: 200px;
background-image: url(“https://image.com/cat”);
background-position: center;
background-repeat: no-repeat;
background-size: contain;
background-attachment: fixed;
}