The Box Model Flashcards
What are the 5 things of the box model
Margin, Border, Padding, Width and Height (Content)
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 of the element
How to change the height and width of an element
Using the height and width properties
Example:
p {
height: 80px;
width: 240px;
}
Border Width
The thickness of the border, can be set in pixels or with the keywords thin, medium, or thick
Border style
The design of the border, there are 10 different ones with the most common being none, dotted, and solid
Border color
The color of the border
How to change how a border looks
With the border property
Example:
p {
border: 3px solid coral;
}
How to change the border radius?
With the border-radius property
Example:
p {
border-radius: 5px;
}
How to make a border a perfect circle?
By setting the height and width to be the same, then making the border radius’ value 50%
How do you change how large the padding is?
Using the padding property
Example:
h1 {
padding: 10px;
}
How do you change the amount of padding on each side?
For 4, 3, and 2 value
By adding multiple numbers
Example:
h1 {
padding: 5px 10px 15px 5px <em>This would mean (top, right, bottom, left)</em>
}
For 3 values, the middle value would set the left and right padding
For 2 values, the first one sets the top and bottom, and the second one does right and left.
*** also works for margin
How to change the margin of an element
Using the margin property
Ex:
p {
margin: 20px;
}
How to change the margin on only one specific side?
Using the margin-right, top, bottom, or left property
Example:
p {
margin-bottom: 15px;
}
What does the auto value do?
You add it in the margin property after setting a width and it will center the element in the margins. The margin must be set to zero first
Ex:
p {
width: 400px;
margin: 0 auto;
}
How to limit how wide or tall something is?
With the min-width, max-width, min-height, and max-height property
Example:
p {
min-width: 300px;
max-width: 600px;
}
Why would you want to limit how wide or tall something is?
To stop it from distorting to much if it is on another screen
How to stop overflow?
Using the overflow property, you can set it to hide, scroll, and visible(the default one)
Example:
p {
overflow: scroll;
}
What is the first thing you usually do when coding in CSS
set the margin and padding of everything to 0
How to change the visibility of an element
Using the visibility property with the value hidden, visible, and collapse
Example:
p {
visibility: hidden;
}