Padding is the space surrounding an element's Content. Padding is spae inside the the container.
At the bottom of this page there is a code editor pre-loaded with the lesson's code.
.withPad {
padding-top: 5px;
padding-right: 10px;
padding-bottom: 15px;
padding-left: 20px;
}
➼ withPad
- This is the class name.
➼ padding-top
- There will be 5px of padding above the cotent.
➼ padding-right
- There will be 10px of padding to the right of the cotent.
➼ padding-bottom
- There will be 15px of padding below the cotent.
➼ padding-left
- There will be 20px of padding to the left of the cotent.
<div class = 'withPad'>
The padding will be placed around the content.
</div>
You can write all padding in one line.
.shortPad{
padding: 5px 10px 15px 20px;
}
➼ shortPad
- This is the class name.
➼ 5px
- padding-top
➼ 10px
- padding-right
➼ 15px
- padding-bottom
➼ 20px
- padding-left
<div class = 'shortPad'>
The padding will be placed around the content.
</div>
Let's look at the CSS and HTML used to make the list above.
If you are not familar with the making lists, check out the lessons on HTML Lists and CSS Lists.
There are four CSS code blocks used to make the list.
There will be a code block for each of the following:
✶Unordered list
✶List items
✶List heading
✶Heading.
First we will create a class for an unordered list.
ul.listClass{
background: #FF3700;
padding: 20px;
border-style: solid;
border-color: orange;
list-style-type: none;
}
➼ ul
- This class is for an unordred list.
➼ listClass
- This is the name of our class.
➼ background
- The background color of the ul element is #FF3700 (orangey color).
➼ padding
- Each side of the element has 20px padding.
(If there is only one number listed after 'padding', that number is applied to the padding on each side)
➼ border-style
- A solid line is used for the element's border.
➼ border-color
- It is orange.
➼ list-style-type
- It is none, which means no bullet points.
Now, let's write our CSS for the individual list items.
ul.listClass li {
background: #FFE53D;
padding: 10px;
border-style: solid;
border-color: orange;
border-width: 2px;
color: #FF520D;
}
➼ ul.listClass
- This code applies to something within the ul listClass.
➼ li
- The code applies to list items (li) inside unordered lists with the class 'listClass'.
➼ background
- The background-color is #FFE53D.
➼ padding
- Each side of the list items will have 10px padding.
➼ border-style
- It is a solid line.
➼ border-color
- It is orange.
➼ border-width
- It is 2px.
➼ color:
- The text color is #FF520D
Now, we will create the heading. I used a span element.
span.listClass {
font-family: Helvetica, sans-serif;
font-size: 24px;
color: #FF520D;
background: yellow;
border-style: solid;
border-width: 2px;
border-color: orange;
padding: 5px;
}
➼ span.listClass
- The class name is listClass and it is exclusive to span elements.
➼ font-family
- Helvetica is the first choice,
if that can't be displayed we will go with anything sans-serif.
➼ font-size
- Its 24px.
➼ color
- Text color is #FF520D.
➼ background
- It is colored yellow.
➼ border-style
- It is a solid line.
➼ border-width
- The border line will have a width of 2px.
➼ border-color
- It is orange.
➼ padding
- Each side of the heading will have 5px padding.
Now, we will style a div container. The list will be inside this div.
div.listClass {
text-align: center;
background-color: black;
padding: 25px;;
font-weight: bold;
}
➼ div.listClass
- This code applies to divs with class listClass.
➼ text-align
- The text will be centered.
➼ background-color
- The background-color is black.
➼ padding
- Each side of the list items will have 25px padding.
➼ font-weight
- Text will be bold.
<div class = 'listClass'>
<span class = 'listClass'>☀ Morning Beverages: ☀</span>
<ul class = 'listClass'>
<li>✶ Coffee ✶</li>
<li>✶ Tea ✶</li>
<li>✶ Red Bull ✶</li>
<li>✶ Juice ✶</li>
<li>✶ Milk ✶</li>
</ul>
</div>
➼ Container
➼ Heading
➼ Unordered List
➼ List Items