CSS Top

CSS Tutorial  >  Position  >  Top

The top property specifies the distance from the top of the element to the default location of the element (when position=relative) or the distance between the top of the element and the top of the container (when position=absolute). This can be specified as a percentage, as a length, or 'auto'.

Let's take a look at two examples:

Example 1: CSS Code

div {
  background-color:#FF00FF;
  width:500px;
  height:60px;
}

p {
  position:relative;
  top:10px;
}

The HTML code,

<div>
  <p>Sample text.
</div>

renders

Sample text.

Without using the top property, the text would have appeared right against the top edge of the pink container. In the above example, the text is 10px from the default location.

Example 2: CSS Code

div {
  background-color:#FF00FF;
  width:500px;
  height:60px;
}

p {
  position:relative;
  top:-10px;
}

The HTML code,

<div>
  <p>Sample text.
</div>

renders

Sample text.

In the above example, the text is 10px above the default location. So, when a relative position is specified, a positive value for "top" means the element is located below the default location, while a negative value for "top" means the element is located above the default location.

Next: CSS Bottom

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.




More 1Keydata Tutorials


Copyright © 2012     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