Home > Tutorials > CSS > Box Attributes

Box Attributes

Now we have some background and foreground colors, and while those may be nice, there's still a lot of formatting to be done. With that, let's look at width, height, padding, and margin:

width
Specifies the width of the current element. Accepted values are any absolute or relative length.
height
Specifies the height of the current element. Accepted values are any absolute or relative length.
padding
Specifies the padding, or the space between content and the edge of the element, of the current element. Accepted values are any absolute or relative length.
margin
Specifies the margin, or the space between elements, of the current element. Accepted values are any absolute or relative length.
float
Specifies which side of the parent element the element should float to. Accepted values:
  • left
  • right

Sizing Diagram

Padding and margin can be specified in a number of ways, as you have four directions (top, bottom, left, and right) to think of. The following are acceptable ways to describe either padding or margin:

  • margin-<direction>: 4px - applies 4px margin to <direction>. <direction> can be top, bottom, left, or right
  • margin: 40% - applies 40% margin to all sides
  • margin: 5px 3px - applies 5px margin to top and bottom, 3px margin to left and right
  • margin: 5px 3% 2px - applies 5px margin to top, 3% margin to left and right, and 2px margin to bottom
  • margin: 5px 4px 3px 2px - applies 5px margin to top, 4px margin to right, 3px margin to bottom, 2px margin to left

Note: padding is used in the exact same manner as above, just substitute "padding" where it says "margin".

Excercise: Open "MyFirstPage.html". Make at least one use of three of the above CSS attributes.

If your code looks like mine, you've succeeded, and can go on to another lesson.

<<PreviousNext>>

Comment on this page:

Your information Name:
Email:
Hide Email?
Enter the 5 characters shown.
Request another image.
Prove your human:
Comments Overall page rating:

Comments

No one has commented on this lesson yet. You can be the first!