Essential Question: How can I apply box model to my CSS style sheet?
Mastery Objectives:
SWBAT create dimensions of an element’s box.
SWBAT create borders of an element’s box.
SWBAT create paddings of an element’s box.
SWBAT create margins of an element’s box.
Resources: The Box Model in Chrome DevTools
The box model is a set of properties used to format parts of an element that take up space on a web page. The model includes the height and width and the element’s padding, border, and margin.
width and height: the width and height of the content area.
padding: The amount of space between the content area and the border.
border: The thickness and style of the border surrounding the content area and padding.
margin: The amount of space between the border and the outside edge of the element.
A border is a line that surrounds a section, like a frame. Borders have the following properties:
width—The thickness of the border. A border’s thickness can be set in pixels or with one of the following keywords: thin, medium, or thick.
style—The design of the border. Web browsers can render any of 10 different styles. Some of these styles include: none, dotted, and solid.
color—The color of the border.
h1 {
border: 4px solid dodgerblue;
}
In the example above, the border has a width of 4 pixels, a style of solid, and a color of dodgerblue.
Border radius rounds out the border.
Padding is the space between the contents of a box and the borders of a box.
If you want to be more specific about the amount of padding on each side of a box’s content, you can use the following properties:
padding-top - the width of the top padding
padding-right - the width of the right padding
padding-bottom - the width of the bottom padding
padding-left - the width of the left padding
30px; padding-left: 20px;
They are formatted together going clockwise starting at the top: padding:
p.content-header {
padding: 4px 10px 6px 7px;
}
padding: 4px - top, 10px- right, 6px - bottom, 7px - left
padding: 4px - top, 10px - right and left, 6px - bottom
padding: 4px - top and bottom, 10px - right and left
Margin refers to the space directly outside of the box.
p {
border: 1px solid dodgerblue;
margin: 10px;
}
margin-top
margin-right
margin-bottom
margin-left
p {
margin: 6px 10px 5px 12px;
}
div{
margin: 0 auto;
}
0 Auto will center the divs in their containing elements. The 0 sets the top and bottom margins to 0 pixels. The auto value instructs the browser to adjust the left and right margins until the element is centered within its containing element.
Top and bottom margins, also called vertical margins, collapse, while top and bottom padding do not.
To accommodate viewing web pages on different devices and screens, CSS offers two properties that can limit how narrow or how wide an element’s box can be sized to:
min-width—this property ensures a minimum width
max-width—this property ensures a maximum width of an element’s box.
p {
min-width: 300px;
max-width: 600px;
}
Overflow property controls decides what happens if an element doesn't fit on the page due to padding, margins, borders, etc. The values are:
hidden—when set to this value, any content that overflows will be hidden from view.
scroll—when set to this value, a scrollbar will be added to the element’s box so that the rest of the content can be viewed by scrolling.
visible—when set to this value, the overflow content will be displayed outside of the containing element. Note, this is the default value.
p {
overflow: scroll;
}
All major web browsers have a default stylesheet they use in the absence of an external stylesheet. These default stylesheets are known as user agent stylesheets. This is an example of how to reset the default values of the user agent stylesheet.
* {
margin: 0;
padding: 0;
}
Elements can be hidden from view with the
Preview: Docs The visibility property in CSS determines whether an element is visible or hidden within the page.
property.
The visibility property can be set to one of the following values:
hidden — hides an element.
visible — displays an element.
collapse — collapses an element.
Directions:
Add a height of 600 pixels to #banner.
Set .pull-quote width to 250 pixels.
Set the #banner .content h1 width to 300 pixels.
Add a dotted blue border with 1-pixel thickness to all h2 headings.
Add a solid, blue border, with a 3 pixel width, to the #banner .content h1 rule.
Set the border radius of #banner .content h1 to 18 pixels. Try experimenting with other border-radius values.
In a single line, set the .navigation li elements to have 18 pixels of padding.
Set the .share a elements to have 15 pixels of padding.
Set the top and bottom padding of h2 elements to 30 pixels and set the left and right padding of h2 elements to 20 pixels.
Change the individual padding declarations on the .pull-quote selector ruleset to use padding shorthand with 2 values. Keep the padding for the top and bottom at 10 pixels and the value for the left and right padding at 20 pixels.
Using two values for the padding property, set the padding of the p element to 10 pixels on the top and bottom and 20 pixels on the left and right.
Set the top margin of p elements to 40 pixels.
Find the three blue boxes at the bottom of the web page. These elements are anchor elements of class .share. Set these .share a elements to have a margin of 15 pixels.
Using two values, set the h2 top and bottom margins to 20 pixels and the left and right margins to 30 pixels.
Set the width of the .pull-quote class elements to 250 pixels.
In one line, set the vertical (top and bottom) margins of the .pull-quote class to 0 and the horizontal (left and right) margins to auto.
Set the vertical margins of the #main element to 0, and the horizontal margins to auto.
set the minimum width of the p element to 250 pixels.
After you’ve done this successfully, resize the browser and notice how the paragraph’s box will no longer shrink below 250 pixels.
Next, set the maximum width of the p element to 700 pixels.
After you’ve done this successfully, resize the browser and notice how the paragraph’s box will no longer expand beyond 700 pixels.
Set the minimum height of the p element to 250 pixels.
After you’ve done this successfully, resize the browser and notice how the height of paragraph’s box will no longer shrink below 250 pixels.
Set the maximum height of the p element to 300 pixels.
In order to see the impact of overflow: scroll, first change the height of the #main element to 1500 pixels.
Set the overflow of the #main element to scroll.
When you scroll down, a second scroll bar should appear over the paragraph section. You may have to expand the browser component in order to see this behavior clearly.
Reset the default margin and padding values for the body.
Take a look at the list items in index.html. Notice that the list item Donate has a class of donate.
Add a class selector ruleset for donate.
Set the visibility to hidden.
<!DOCTYPE html>
<html>
<head>
<title>Boston Harbor</title>
<link href="https://fonts.googleapis.com/css?family=Amatic+SC|Raleway:100,200,600,700" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navigation">
<ul>
<li>LOCAL</li>
<li>NATIONAL</li>
<li class="logo">Boston Harbor Conservation</li>
<li>GLOBAL</li>
<li>OPED</li>
<li class="donate">DONATE</li>
</ul>
</nav>
<div id="banner">
<div class="content">
<h1>Conservation Efforts at Boston Harbor</h1>
</div>
</div>
<div id="main" class="content">
<h3>Saying Goodbye to Dirty Water</h3>
<span class="byline">WRITTEN BY: Wikipedia</span>
<p>The health of the harbor quickly deteriorated as the population of Boston increased. As early as the late 19th century Boston citizens were advised not to swim in any portion of the Harbor. In the 19th century, two of the first steam sewage stations were built (one in East Boston and one later on Deer Island). With these mandates, the harbor was seeing small improvements, but raw sewage was still continuously pumped into the harbor. In 1919, the Metropolitan District Commission was created to oversee and regulate the quality of harbor water. However, not much improvement was seen and general public awareness of the poor quality of water was very low. In 1972, the Clean Water Act was passed in order to help promote increased national water quality.</p>
<p>Since the mid-1970s organizations within the Boston community have battled for a cleaner Boston Harbor. More recently, the harbor was the site of the $4.5 billion Boston Harbor Project. Failures at the Nut Island sewage treatment plant in Quincy and the companion Deer Island plant adjacent to Winthrop had far-reaching environmental and political effects. Fecal coliform bacteria levels forced frequent swimming prohibitions along the harbor beaches and the Charles River for many years. The city of Quincy sued the Metropolitan District Commission (MDC) and the separate Boston Water and Sewer Commission in 1982, charging that unchecked systemic pollution of the city's waterfront contributed to the problem. That suit was followed by one by Conservation Law Foundation and finally by the United States government, resulting in the landmark court-ordered cleanup of Boston Harbor.</p>
<p>The lawsuits forced then-Massachusetts Governor Michael Dukakis to propose separating the water and sewer treatment divisions from the MDC, resulting in the creation of the Massachusetts Water Resources Authority in 1985. The slow progress of the cleanup became a key theme of the 1988 U.S. presidential election as George H. W. Bush defeated Dukakis partly through campaign speeches casting doubt on the governor's environmental record, which Dukakis himself had claimed was better than that of Bush. The court-ordered cleanup continued throughout the next two decades and is still ongoing.</p>
<p>Before the clean-up projects, the water was so polluted that The Standells released a song in 1965 called "Dirty Water" which referred to the sorry state of the Charles River. Neal Stephenson, who attended Boston University from 1977 to 1981, based his second novel, Zodiac, around pollution of the harbor.</p>
<p>Since the writing of the song, the water quality in both the Harbor and the Charles River has significantly improved, and the projects have dramatically transformed Boston Harbor from one of the filthiest in the nation to one of the cleanest. Today, Boston Harbor is safe for fishing and for swimming nearly every day, though there are still beach closings after even small rainstorms, caused by bacteria-laden storm water and the occasional combined sewer overflow.</p>
<p>In 2022, pieces of plastic transmission line used in rock explosives, (known as explosive shock tubing) began washing up on coastal shores of Cape Cod and Rhode Island. This led to an investigation that was conducted by the U.S. Army Corps of Engineers, it was suspected to have been related to a concluded Boston Harbor dredging project. The outcome was to seek to find methods to prevent future environmental impacts from reoccurring.</p>
<div class="pull-quote">
<h2>AQUACULTURE</h2>
</div>
<p>In 1996, the Boston Globe reported that Mayor Thomas Menino and MIT engineer Clifford Goudey were planning a program to use the great tanks on Moon Island as a fish farm or a temporary home for tuna or lobster in an attempt to implement a recirculating aquaculture system in Boston Harbor. The prices of both these fish types vary by season. The plan was to collect and store fish in the tanks and sell the fish at higher prices when they were out of season. Nothing has come of this plan to date. </p>
</div>
<div class="share">
<a href="#">SHARE</a>
<a href="#">FAVORITE</a>
<a href="#">READ</a>
</div>
</body>
</html>
body {
background-color: white;
font-family: 'Raleway', sans-serif;
}
.navigation ul {
margin: 0;
padding: 0;
text-align: center;
}
.navigation li {
font-weight: 100;
letter-spacing: 2px;
padding: 20px;
}
.navigation li.logo {
color: black;
font-size: 18px;
font-weight: 700;
letter-spacing: 4px;
}
#banner {
background-image: url("https://th.bing.com/th/id/OSK.HERONK9FRCtEfaxxpaqDwaXb0sPboTTsFdqVTEMVgefJVQI?rs=1&pid=ImgDetMain");
background-size: cover;
background-position: bottom center;
height: 700px;
width: 100%;
}
#banner .content h1 {
border: 3px solid white;
position: relative;
top: 50px;
width: 400px;
margin: 0 auto;
}
#main {
margin: 0 auto;
padding: 40px;
text-align: center;
width: 400px;
height: 1000px;
overflow: scroll;
}
h1 {
color: white;
font-size: 42px;
font-weight: 600;
text-align: center;
}
h2 {
border: 1px dotted red;
color: red;
font-size: 14px;
line-height: 48px;
padding: 20px 30px;
margin: 30px 20px;
text-align: center;
}
h3 {
color: red;
font-size: 26px;
font-weight: 700;
padding: 20px 10px;
}
p {
color: grey;
font-size: 16px;
line-height: 48px;
margin-top: 60px;
padding: 10px 20px;
}
.pull-quote {
margin: 0 auto;
width: 400px;
}
.byline {
border-bottom: 1px solid LightGrey;
border-top: 1px solid LightGrey;
color: DarkGrey;
font-size: 14px;
font-weight: 200;
}
.share {
border: 1px solid LightGrey;
padding: 40px 0px;
position: relative;
text-align: center;
width: 100%;
}
.share a {
background: red;
border: 1px solid red;
border-radius: 3px;
color: white;
display: inline-block;
margin: 10px;
padding: 14px;
text-decoration: none;
}
.share a:hover {
background: white;
border: 1px solid red;
color: red;
}