CSS2快速参考(3)
作者:周晓阳 来源:网页制作大宝库 添加时间:2006-5-21 9:49:17在以前的HTML里,元素的位置只能靠元素的依次排列觉得,而在CSS里你可以更精确的定位元素。Netscape曾提出过Layer标记,它对于精确布局很有好处,但是并没有被W3C承认,W3C在CSS提出了类似于Layer标记的功能。
position属性:
position属性用来决定元素的位置类型,详见属性:
属性名称: 'position'
属性值: absolute | relative | static
初始值: static
适合对象: 所有元素
是否继承: no
百分比备注: 被禁止
其属性值分别代表:
absolute:屏幕上的绝对位置。
relative:屏幕上的相对位置。
static:固有位置。
direction属性:
direction属性决定BOX的排列方向,详见属性:
属性名称: 'direction'
属性值: ltr| rtl
初始值: ltr
适合对象: 所有元素
是否继承: yes
百分比备注: 被禁止
float和clear属性:
在HTML中图片可以选择飘浮的位置,现在BOX对象通过CSS对于也可以选择飘浮的位置。改变BOX的float属性,BOX将飘浮在其他元素的左或右方:
属性名称: 'float'
属性值: left| right|none
初始值: none
适合对象: 所有元素
是否继承: no
百分比备注: 被禁止
例如:
<STYLE type="text/css">
IMG { float: left }
BODY, P, IMG { margin: 2em }
</STYLE>
<BODY>
<P>
<IMG src="/edu/files/pic/2006-5/21/0652109491760572.gif"”,其余部分以红色为背景色*/
background-attachment属性表示在滚动整个文档时,背景图片的显示方式。它的属性值有两种:fixed和scroll,fixed相当于IE4里的水印效果,也就是说在拖动文档时,背景相对是静止的,scroll则和文档一起滚动。
background-position属性用来指定背景图片显示的位置:
属性名称: 'background-position'
属性值: [<percentage> | <length> ]{1,2} | [top | center | bottom] || [left | center | right]
初始值: 0% 0%
适合对象: 容器元素
是否继承: no
百分比备注: refer to the size of the element itself
其中属性值含义为:
“top left”和“left top”表示“0% 0%”。
“top”、“top center”和“center top”表示“50% 0%”。
“right top”和“top right”都表示“100% 0%”。
“left”、“left center”和“center left”表示“0% 50%”。
“center”和“center center”表示“50% 50%”。
“right”、“right center”和“center right”都表示“100% 50%”。
“bottom left”和“left bottom”表示“0% 100%”。
“bottom”、“bottom center”和“center bottom”都表示“50% 100%”
“bottom right”和“right bottom”表示“100% 100%”。
例如:
BODY { background: url(banner.jpeg) right top } /* 100% 0% */
BODY { background: url(banner.jpeg) top center } /* 50% 0% */
BODY { background: url(banner.jpeg) center } /* 50% 50% */
BODY { background: url(banner.jpeg) bottom } /* 50% 100% */
background属性是以上背景属性的快捷方式,属性和顺序如下:
属性名称: 'background'
属性值: <'background-color'> || <'background-image'> || <'background-repeat'> || <'background-attachment'> || <'background-position'>
适合对象: 所有元素
是否继承: no
百分比备注: 只在background-position中容许使用
站内搜索