Chinaunix首页 | 论坛 | 博客
  • 博客访问: 96130
  • 博文数量: 34
  • 博客积分: 925
  • 博客等级: 准尉
  • 技术积分: 350
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-15 11:52
文章分类

全部博文(34)

文章存档

2011年(34)

我的朋友

分类: 系统运维

2011-08-18 14:14:12

CSS Positioning

The term "CSS positioning" refers to using CSS to position elements on your HTML page. CSS allows you to position any element precisely where you want it. You can specify whether you want the element positioned relative to its natural position in the page or absolute based on its parent element.

Absolute positioning can be very useful for creating advanced layouts and cool visual effects such as overlapping elements to present a layered effect.

Relative Positioning

To perform relative positioning in CSS you use position:relative; followed by the desired offset from either top, right, bottom or left

  1. <div style="position:relative;left:80px;background-color:yellow;width:100px;">
  2. This div has relative positioning.
  3. </div>
This results in:
This div has relative positioning.

This example offsets the element 80 pixels from the left of where it would have been. If we had specified top, it would appear 80 pixels below where it would have been. It's important to note that other elements are not affected by this element's offset. Therefore, overlapping may occur.

Absolute Positioning

To perform absolute positioning in CSS you use position:absolute; followed by the desired offset.

  1. <div style="position:absolute;top:100px;left:60px;background-color:yellow;">

  2. This div is absolutely positioned 100 pixels from the top and 60 pixels from the left of its containing block.

  3. </div>

Fixed Positioning

Fixed positioning allows you to fix the position of an element to a particular spot on the page - regardless of scrolling.

  1. <div style="position:fixed;top:100px;left:60px;width:180px;background-color:red;">

  2. This div is using a fixed position of 100 pixels from the top and 60 pixels from the left of its containing block. When this page scrolls, this box will remain in a fixed position - it won
阅读(205) | 评论(0) | 转发(0) |
0

上一篇:CSS Height and Width

下一篇:CSS Float

给主人留下些什么吧!~~