Professional Documents
Culture Documents
Understanding The CSS Syntax: h1 (Color) :red
Understanding The CSS Syntax: h1 (Color) :red
rule
selector
h1 {
color:red; declaration
} property value
More about Selectors
IDs #main-title {
<h1 id="main-title">
color: red;
Set style to one </h1>
}
specific element
Cascading Specificity
Multiple Rules can apply to the same Resolve conflicts arising from multiple
Element Rules
Inline Styles
#ID selectors
Cascading Specificity
Multiple Rules can apply to the same Resolve conflicts arising from multiple
Element Rules
Selector Hierarchy
div {
color: red; <div>
} <div>
<h1>Inherited!</h1>
</div>
p { <p>Overwritten</p>
<p>Inherited!</p>
color: green; <div>Inherited!</div>
} <article>
<p>Overwritten</p>
<p>Inherited!</p>
</article>
<p>Overwritten</p>
<p>Inherited!</p>
Parent styles are inherited by </div>
child elements if not overwritten!
Understanding Combinators
div > p { div p {
} }
Combinators – Adjacent Sibling
+ Adjacent Sibling
h2 + p { <div>
color: red; <h2>Not applied</h2>
} <p>CSS applied</p>
<h2>Not applied</h2>
<h3>Not applied</h3>
<p>Not applied</p>
<h2>Not applied</h2>
Elements share the same <p>CSS applied</p>
parent </div>
Second element comes
immediately after first element
Combinators – General Sibling
~ General Sibling
h2 ~ p { <div>
color: red; <h2>Not applied</h2>
} <p>CSS applied</p>
<h2>Not applied</h2>
<h3>Not applied</h3>
<p>CSS applied</p>
</div>
Element share the same
parent
Second element comes after
first element
Combinators – Child
> Child
div > p { <div>
color: red; <div>Not applied</div>
} <p>CSS applied</p>
<div>Not applied</div>
<article>
<p>Not applied</p>
</article>
Second element is a direct <p>CSS applied</p>
child of first element </div>
Combinators – Descendant
Descendant
div p { <div>
color: red; <div>Not applied</div>
} <p>CSS applied</p>
<div>Not applied</div>
<article>
<p>CSS applied</p>
</article>
Second element is a <p>CSS applied</p>
descendant of the first element </div>
Value Types
background:
display: block; background: red; height: 100px;
url(…);
transform:
overflow: auto; color: #fa923f; width: 20%;
scale(…);