box model Flashcards
Name all sections of the box model
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.
An element has 2 dimensions how can we change the height and width
p {
height: 80px;
width: 240px;
}
What is a border
A border is a line that surrounds an element, like a frame around a painting.
what properties can be set with the border
Borders can be set with a specific width, style, and color
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. Web browsers can render colors using a few different formats, including 140 built-in color keywords.
example
p {
border: 3px solid coral;
}
In the example above, the border has a width of 3 pixels, a style of solid, and a color of coral. All three properties are set in one line of code.
The default border is medium none color, where color is the current color of the element. If width, style, or color are not set in the CSS file, the web browser assigns the default value for that property.
how can you modify the radius of the box
order-radius property.
div.container {
border: 3px solid blue;
border-radius: 5px;
}
what is padding
The space between the contents of a box and the borders of a box is known as padding. Padding is like the space between a picture and the frame surrounding it. In CSS, you can modify this space with the padding property.
p.content-header {
border: 3px solid coral;
padding: 10px;
}
what is a use of using the padding
The padding property is often used to expand the background color and make the content look less cramped
how can you make the padding more specific
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 padding-right padding-bottom padding-left
what is the use of padding short hand
Another implementation of the padding property lets you specify exactly how much padding there should be on each side of the content in a single declaration. A declaration that uses multiple properties as values is known as a shorthand property.
Padding shorthand lets you specify all of the padding properties as values on a single line:
padding-top padding-right padding-bottom padding-left
what is the 4 value padding short hand
4 Values
p.content-header {
padding: 6px 11px 4px 9px;
}
In the example above, the four values 6px 11px 4px 9px correspond to the amount of padding on each side, in a clockwise rotation. In order, it specifies the padding-top value (6px), the padding-right value (11px), the padding-bottom value (4px), and the padding-left value (9px) of the content.
what is the the 2 value shorthand
2 Values
p.content-header {
padding: 5px 10px;
}
And finally, if the top and bottom sides can be equal, and the left and right sides can be equal, you can specify 2 values. The first value sets the padding-top and padding-bottom values (5px), and the second value sets the padding-left and padding-right values (10px).
what is margin
Margin refers to the space directly outside of the box. The margin property is used to specify the size of this space.
example of margin
p {
border: 1px solid aquamarine;
margin: 20px;
}
The code in the example above will place 20 pixels of space on the outside of the paragraph’s box on all four sides. This means that other HTML elements on the page cannot come within 20 pixels of the paragraph’s border
how to be more specific with the margin
margin-top
margin-right
margin-bottom
margin-left