CSS Positioning
来源:互联网 发布:如何破解网络尖兵 编辑:程序博客网 时间:2024/05/16 08:51
Positioning
The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element's content is too big.
Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method.
There are four different positioning methods.
Static Positioning
HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page.
Static positioned elements are not affected by the top, bottom, left, and right properties.
Fixed Positioning
An element with fixed position is positioned relative to the browser window.
It will not move even if the window is scrolled:
Example
p.pos_fixed{
position:fixed;
top:30px;
right:5px;
}
Try it yourself »
Note: IE7 and IE8 support the fixed value only if a !DOCTYPE is specified.
Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist.
Fixed positioned elements can overlap other elements.
Relative Positioning
A relative positioned element is positioned relative to its normal position.
Example
h2.pos_left{
position:relative;
left:-20px;
}
h2.pos_right
{
position:relative;
left:20px;
}
Try it yourself »
The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow.
Example
h2.pos_top{
position:relative;
top:-50px;
}
Try it yourself »
Relatively positioned elements are often used as container blocks for absolutely positioned elements.
Absolute Positioning
An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>:
Example
h2{
position:absolute;
left:100px;
top:150px;
}
Try it yourself »
Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist.
Absolutely positioned elements can overlap other elements.
Overlapping Elements
When elements are positioned outside the normal flow, they can overlap other elements.
The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others).
An element can have a positive or negative stack order:
Example
img{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
Try it yourself »
An element with greater stack order is always in front of an element with a lower stack order.
Note: If two positioned elements overlap, without a z-index specified, the element positioned last in the HTML code will be shown on top.
- CSS Positioning
- CSS Positioning
- CSS Positioning
- CSS 定位 (Positioning)
- CSS 定位 (Positioning)
- CSS 定位 (Positioning)
- CSS 定位 (Positioning)浅析
- CSS 定位 (Positioning)
- css定位(positioning)
- CSS 定位 (Positioning)
- CSS 定位 (Positioning)浅析
- 10022---CSS Positioning(定位)
- <css 十>Positioning
- CSS 定位(Positioning)
- CSS-Positioning(定位)
- CSS Positioning(定位)
- CSS Positioning(定位)
- CSS-Positioning(定位)
- 面向对象编程(C++描述)总结
- C语言回调函数与函数指针
- 何为NDK ?
- No 4 · 获取客户端和服务器端IP地址
- android:View cannot be resolved to a type
- CSS Positioning
- Qt(学习)windows下Qt&MySQL数据库配置过程
- Android 拷贝/粘贴(Copy/Paste)
- No 5 · JMail 发送和接受邮件
- 项目".csproj"所需的应用程序未安装,确保已安装项目类型(.csproj)的应用程序
- 在任意位置获取Application Context
- Android深入浅出之Audio第一部分 AudioTrack分析
- Android 音频视频媒体框架
- CSS Horizontal Align