CSS Padding

CSS Tutorial  >  Padding

As we saw from the box model, padding is the space just outside the content area, and just inside the border area. In a box, there are four sides. So, we can specify paddings up to the 4 sides, plus a general padding property:

  • padding-top
  • padding-right
  • padding-bottom
  • padding-left

    A fifth property, padding, is used as a shortcut for the above four properties.

    paddings can be specified in 3 ways: length, percentage, or auto. Let's take a look at an example:

    #container {
      padding-top:15px;
      padding-left:5px;
      padding-right:30px;
      padding-bottom:40px;
      border: 1px solid 000000;
    }

    The following HTML

    <div id="container">
    This is an example for the padding
    </div>

    renders the following:

    This is an example for the padding

    Notice the padding between the box and the top, left, bottom, and right of the light green area are 15px, 5px, 40px, and 30px, respectively.

    padding shortcuts

    All four paddings can be specified on a single line using the "padding" property. The syntax is as follows:

    padding: [padding-top] [padding-right] [padding-bottom] [padding-left]

    The order is very important here. The first element is always the top padding, the second is always the right padding, the third is always the bottom padding, and the fourth is always the left padding.

    Next: CSS Background



    Copyright © 2013   1keydata.com   All Rights Reserved   Privacy Policy

  • CSS Tutorial
    CSS Syntax
    Apply CSS
    CSS Media Types
    CSS Cascade
    CSS Inheritance
    CSS Class ID
    CSS Div Span
    CSS Length Units

    CSS Box Model
    CSS Margin
    CSS Border
    CSS Padding
    CSS Background
      CSS Background-attachment
      CSS Background-color
      CSS Background-image
      CSS Background-position
      CSS Background-repeat
    CSS Color
    CSS Font
    CSS Link
    CSS List
    CSS Table
    CSS Position
      CSS Absolute
      CSS Relative
      CSS Fixed
      CSS Static
      CSS Top
      CSS Bottom
      CSS Left
      CSS Right
      CSS Overflow
      CSS Z-Index
    CSS Text
    CSS Float
    CSS Clear
    CSS Cursor
    CSS Wrap

    CSS Codes

    Resources

    CSS Tutorial German