Essential Question: What are the five properties that help adjust HTML elements in the browser?
Mastery Objective:
SWBAT modify z-index in CSS.
SWBAT adjust position in CSS.
SWBAT adjust display in CSS.
SWBAT adjust float in CSS.
SWBAT use clear in CSS.
What does Normal Flow Mean in CSS?
The position property allows you to specify the position of an element.
When set to relative, an element’s position is relative to its default position on the page.
When set to absolute, an element’s position is relative to its closest positioned parent element. It can be pinned to any part of the web page, but the element will still move with the rest of the document when the page is scrolled.
When set to fixed, an element’s position can be pinned to any part of the web page. The element will remain in view no matter what.
When set to sticky, an element can stick to a defined offset position when the user scrolls its parent container.
The z-index of an element specifies how far back or how far forward an element appears on the page when it overlaps other elements.
The display property allows you to control how an element flows vertically and horizontally in a document.
inline elements take up as little space as possible, and they cannot have manually adjusted width
or height.
block elements take up the width of their container and can have manually adjusted heights.
inline-block elements can have set width and height, but they can also appear next to each other and do not take up their entire container width.
The float property can move elements as far left or as far right as possible on a web page.
You can clear an element’s left or right side (or both) using the clear property.
Directions:
In style.css, add a declaration to the .question ruleset that sets the position to static.
Notice that setting position to static does nothing. That’s because static simply refers to the default behavior. CSS Layout - The position Property
Inside the .question ruleset, change the position property to relative. CSS Layout - The position Property
Offset .question 40 pixels from the top.
Set the position inside of the header ruleset to absolute. CSS Layout - The position Property
Notice how it’s now removed from the normal flow of the document, and covering the welcome section.
When you changed the position to absolute, you may have noticed that the header shrunk horizontally. We’ll learn why in a later exercise. For now, set the width property of the header to 100%.
Change the position property inside of the header rule to fixed. Scroll up and down the web page. What do you notice? CSS Layout - The position Property
Notice that part of the “Welcome” section is now covered up by the header. That’s because when we changed the position of the header to fixed, we removed it from the flow of the html document. Let’s fix that. Set the position of the .welcome element to relative. CSS Layout - The position Property
Offset the “Welcome” section by 200 pixels from the top. Everything might not be displaying correctly just yet; we’ll fix it in a later exercise.
Change the position of the elements with the class question to sticky. CSS Layout - The position Property
Set the z-index of the header to 10. Notice how the header is no longer covered by other elements when you scroll! CSS Layout - The z-index Property
In index.html, add opening and closing <strong></strong> tags around the word “Welcome”. Notice that the element does not move. That’s because <strong> elements are inline, so they can share lines with other elements.
In index.html, add a <footer> element at the bottom of the document, right above the closing </body> tag.
Nothing changed! That’s because the <footer> element is empty. Add an <h3> element inside of the footer that says “Thanks for taking our survey!”
To improve the appearance of the web page, set the height of the footer to 100 pixels in style.css.
Let’s fix the display of the list elements in the menu at the top of the page.
Set the display property of <li> elements to inline-block. CSS Layout - inline-block
Set the width of the li elements to 80 pixels.
Now, we can reduce the top offset of the “Welcome” section. Set it to 50 pixels.
Set the display property of .answer elements to inline-block. CSS Layout - inline-block
Add a declaration to the .answer ruleset that sets the float property to left. CSS Layout - float and clear
Take a look at the .answer divs on the web page. They have been floated to the left, but the .question divs are touching the .answer divs on the right, let’s fix this.
In the .question selector, set the clear property to left. Notice how the questions moved. CSS Layout - clear and clearfix
On second thought, this layout is not looking so good. Remove the float property from .answer selector ruleset. CSS Layout - float and clear
body {
background-color: #FFF;
margin: 0 auto;
}
header {
background-color: #466995;
border-bottom: 1px solid #466995;
}
ul {
margin: 30px auto;
padding: 0 20px;
text-align: center;
}
li {
color: #FFF;
font-family: 'Oswald', sans-serif;
font-size: 16px;
font-weight: 300;
text-transform: uppercase;
}
li:hover {
color: #DBE9EE;
}
h1 {
color: #466995;
font-family: 'Oswald', sans-serif;
font-size: 32px;
font-weight: 300;
text-transform: uppercase;
}
h2 {
color: #333;
font-family: 'Varela Round', sans-serif;
font-size: 26px;
font-weight: 100;
margin: 0 auto 20px auto;
}
h3 {
color: #466995;
font-family: 'Oswald', sans-serif;
font-size: 18px;
text-align: center;
font-weight: 700;
text-transform: uppercase;
padding: 30px;
}
h4 {
color: #466995;
font-family: 'Oswald', sans-serif;
font-size: 18px;
font-weight: 300;
letter-spacing: 2px;
text-align: center;
text-transform: uppercase
}
p {
color: #333;
font-family: 'Varela Round', sans-serif;
font-size: 18px;
}
footer {
background-color: #DBE9EE;
text-align: center;
}
.welcome {
background-color: #DBE9EE;
box-sizing: border-box;
padding: 40px;
text-align: center;
width: 100%;
}
.question {
text-align: center;
}
.answer {
border: 1px solid #466995;
margin: 20px;
}
.answer:hover {
background: #C0D6DF;
color: #FFF;
}
<!DOCTYPE html>
<html>
<head>
<title>Please Participate in Our Survey!</title>
<link href="https://fonts.googleapis.com/css?family=Oswald:300,700|Varela+Round" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<ul>
<li>Question 1</li>
<li>Question 2</li>
<li>Question 3</li>
<li>Question 4</li>
<li>Question 5</li>
</ul>
</header>
<div class="welcome">
<h1>Welcome to our survey!</h1>
<p>We're looking forward to getting your answers so we can make sure our products and services are the best they can be!</p>
</div>
<div class="question">
<h4>Question 1</h4>
<h2>I like participating in physical activity such as running, swimming, or biking.</h2>
<div class="answer">
<h3>Disagree</h3>
</div>
<div class="answer">
<h3>Neutral</h3>
</div>
<div class="answer">
<h3>Agree</h3>
</div>
</div>
<div class="question">
<h4>Question 2</h4>
<h2>I try to keep up to date with the latest fashion in active wear.</h2>
<div class="answer">
<h3>Disagree</h3>
</div>
<div class="answer">
<h3>Neutral</h3>
</div>
<div class="answer">
<h3>Agree</h3>
</div>
</div>
<div class="question">
<h4>Question 3</h4>
<h2>I purchase clothing online regularly.</h2>
<div class="answer">
<h3>Disagree</h3>
</div>
<div class="answer">
<h3>Neutral</h3>
</div>
<div class="answer">
<h3>Agree</h3>
</div>
</div>
<div class="question">
<h4>Question 4</h4>
<h2>I try to buy goods that are designed and/or manufactured in my home country.</h2>
<div class="answer">
<h3>Disagree</h3>
</div>
<div class="answer">
<h3>Neutral</h3>
</div>
<div class="answer">
<h3>Agree</h3>
</div>
</div>
<div class="question">
<h4>Question 5</h4>
<h2>I look to famous athletes when trying to choose what to wear when training.</h2>
<div class="answer">
<h3>Disagree</h3>
</div>
<div class="answer">
<h3>Neutral</h3>
</div>
<div class="answer">
<h3>Agree</h3>
</div>
</div>
</body>
</html>