CSS Box Model : Height and Width
THE BOX MODEL
An element’s content has two dimensions: a height and a width. By default, the dimensions of an HTML box are set to hold the raw contents of the box.
The CSS height
and width
properties can be used to modify these default dimensions.
p {
height: 80px;
width: 240px;
}
In this example, the height
and width
of paragraph elements are set to 80 pixels and 240 pixels, respectively — the px
in the code above stands for pixels.
Pixels allow you to set the exact size of an element’s box (width and height). When the width and height of an element are set in pixels, it will be the same size on all devices — an element that fills a laptop screen will overflow a mobile screen.
Instructions:
1.Add a height of 700 pixels to #banner
.
Hint:
The #banner
ruleset starts on line 24. To set the height of its content, add another declaration using the height
property with a value of 700px
.
2.Set .pull-quote
width to 350 pixels.
Hint:
The .pull-quote
ruleset is on line 72. To set the width of the its content, create a declaration using the width
property with a value of 350px
.
3.Set the #banner .content h1
width to 400 pixels.
Hint:
The #banner .content h1
starts on line 32. Use the same technique as above to set the width. You’ve got this!
Question
Why do we need to set height and width, 100 and why some elements don’t have it?
Answer
It is not always necessary to set a height and width. Elements by default are block elements and will have the same width as the container, and their height will vary depending on their content. The element’s measurements will be decided by what purpose we want it to have, just like news paper’s editors will arrange the columns, sometimes we will want to have an image that will only cover half of the screen, or even less. That is when we could use height and/or width measurements.
Comments
Post a Comment