当前位置: 首页 > 网络学院 > 网页制作基础教程 > CSS > CSS 边距
The CSS margin properties define the space around elements.
CSS的边距属性定义元素周围的空间范围
Set the left margin of a text
This example demonstrates how to set the left margin of a text.
设置文字左边距
Set the right margin of a text
This example demonstrates how to set the right margin of a text.
设置文字右边距
Set the top margin of a text
This example demonstrates how to set the top margin of a text.
设置文字顶边距
Set the bottom margin of a text
This example demonstrates how to set the bottom margin of a text.
底部边距
All the margin properties in one declaration
This example demonstrates how to set a shorthand property for setting all of the margin properties in one declaration.
快速定义四边边距
The CSS margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used to change all of the margins at once.
CSS边距定义元素周围的空间范围。它可让内容重叠。也可用分离的属性分别对上,下,左,右进行样式改变。用margin属性可以快速的设置所有边距。
Note: Netscape and IE give the body tag a default margin of 8px. Opera does not! Instead, Opera applies a default padding of 8px, so if one wants to adjust the margin for an entire page and have it display correctly in Opera, the body padding must be set as well!
注意: 网景和IE默认给body标签加上了8px的边距。OPERA就没有这样的情况,相反的,OPERA有个默认的8px填充,所以要让页面在几个不同主流浏览器上的效果都相同就需要将属性设置妥当!
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
浏览器支持:IE: Internet Explorer, F: Firefox, N: Netscape
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is defined (CSS1 or CSS2).
W3C:里面的数字代表CSS版本号
Property属性 | Description描述 | Values值 | IE | F | N | W3C |
---|---|---|---|---|---|---|
margin | A shorthand property for setting the margin properties in one declaration 快速设置各边距属性 | margin-top margin-right margin-bottom margin-left | 4 | 1 | 4 | 1 |
Sets the bottom margin of an element 设置底部边距 | auto length % | 4 | 1 | 4 | 1 | |
Sets the left margin of an element 设置左部边距 | auto length % | 3 | 1 | 4 | 1 | |
Sets the right margin of an element 设置右部边距 | auto length % | 3 | 1 | 4 | 1 | |
margin-top | Sets the top margin of an element 设置上部边距 | auto length % | 3 | 1 | 4 | 1 |