The Box Model
An HTML element can take up more space on a page than its content itself. An element is surrounded by 3 other parts:
- The padding around the element
- The border around the padding
- The margin outside the border, to separate from other elements.
For example, here's a paragraph with a padding, border and margin:
The quick brown fox packed my box with five dozen liquor jugs and then jumped over the lazy dogs.
Here's each part marked:
The element itself is in the middle, surrounded by padding in the same color, then a border, and finally a (white) margin on the outside.
The paragraph above uses the following CSS:
.green-box{ margin: 15px; border: solid 5px blue; padding: 10px; background-color: green; }
Hover above for more info
And HTML:
<p class="green-box">The quick brown fox packed my box with five dozen liquor jugs and then jumped over the lazy dogs.</p>
By default, the padding, border and margin are all outside the specified width of the element itself. If you want to change that, you can read about box-sizing.
Store Page
Selectors added a margin to an image on the store page. Can you now add a border to the image?
Challenge
Add a CSS style that adds a solid gray border 2px wide to the image.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Cher
Sep 11, 3:53 AMWhat problem with my code?
Learneroo
Sep 11, 9:54 AMDid you select the image?
Cher
Sep 11, 10:42 AMYes sir, here is my code:
/* CSS */
#sample-pic{
border: solid 2px gray;
}
Learneroo
Sep 11, 11:41 AMOK but I see that your code passed, so there shouldn't be a problem.