
styles.css
from last classsection {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
.orange {
color: #f0a202
}
index.html
from last class<head>
...
<link rel="stylesheet" href="styles.css" />
<title>Welcome to HCDD 340!</title>
</head>
section {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
section {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
section {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
Matches all <section>
elements
h4 {
font-size: 1em;
}
Matches all <h4> elements
.orange {
color: #f0a202
}
styles.css
<h1 class="orange">HCDD 340</h1>
<h1>Goals</h1>
index.html
. is in CSS rules, but not in html
.orange {
color: #f0a202
}
styles.css
<h1 class="orange another-class some-other-class">HCDD 340</h1>
<h1>Goals</h1>
index.html
Still matches (all elements containing the given class)
#penn-state {
border: 1px solid #96BEE6;
}
styles.css
<div id="penn-state">
We are!
</div>
index.html
# is in CSS rules, but not in html
[data-college] {
color: #96BEE6;
}
styles.css
<div data-college="IST">Information Sciences and Technology</div>
<div data-college="HHD">Health and Human Development</div>
index.html
Both <div>s will match (i.e.,
attribute “college” is present)
[data-college="IST"] {
color: #96BEE6;
}
styles.css
<div data-college="IST">Information Sciences and Technology</div>
<div data-college="HHD">Health and Human Development</div>
index.html
What happens here?
Only the first <div> will be
selected
h2:hover {
color: blue;
}
Change outline when <h2> is
hovered
p:nth-child(even) {
background: blue;
}
All even paragraphs will have blue
background
:first-child:last-child:visitedp::first-letter {
color: goldenrod;
font-weight: bold;
}
Changes the first letter of each paragraph — check it out
.exciting-text::after {
content: " <- EXCITING!";
color: darkgreen;
font-weight: bolder;
}
.boring-text::after {
content: " <- BORING";
color: darkviolet;
font-weight: bolder;
}
Check out the example
h1, h2, h3, h4, h5 {
margin: 0 0 20px 0;
line-height: 1.2;
font-weight: bold;
}
Separated by commas
p strong {
color: red;
}
All <strong> elements within
<p> elements will have red color
li {
list-style-type: disc;
}
li li {
list-style-type: circle;
}
css
<ul>
<li>Item 1
<ul>
<li>Subitem A</li>
<li>Subitem B</li>
</ul>
</li>
html
div > p {
color: red;
}
Only the direct children will be selected (more restrictive than descendant combinator)
span {
background-color: aqua;
}
div > span {
background-color: yellow;
}
styles.css
<div>
<span>
Span #1, in the div.
<span>Span #2, in the span that's in the div.</span>
</span>
</div>
<span>Span #3, not in the div at all.</span>
index.html
Check it out!
img + p {
font-weight: bold;
}
A paragraph that immediately follows an image (within same parent) will have bold text
img ~ p {
}
Any paragraph that immediately follows an image (within
same parent) will have bold text
p ~ span {
color: red;
}
styles.css
<article>
<span>S1</span>
<p>P1</p>
<code>C1</code>
<span>S2</span>
<p>P3</p>
<h1>H1</h1>
<span>S3</span>
</article>
<span>S4</span>
index.html
Check it out!
A browser will apply default styles
h1 {
color: red;
}
h1 {
color: blue;
}
h1 {
color: red;
}
h1 {
color: blue;
}
The color will be blue
button {
background: yellow;
}
styles.css
...
<link rel="stylesheet"
href="/styles.css" />
...
...
<button> I am a button </button>
<style>
button { background: pink; }
</style>
</body>
index.html
pink — embedded style is more
immediate
.branding {
color: blue;
}
button {
color: red;
}
<button class="branding">
Hello, Specificity!
</button>
Blue — check it out!
!important to change importance
index.html in Chrome/Firefoxstyles.css<h2>:
#333333
<h2>: