CSS margin-top 属性
CSS margin-top 属性用来设置元素的顶部外边距,你也可以使用负值。
实例
设置 p 元素的上外边距:
<html><head><style type="text/css">p.topmargin {margin-top: 5cm}</style></head><body><p>这个段落没有指定外边距。</p><p class="topmargin">这个段落带有指定的上外边距。</p></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 属性 | |||||
|---|---|---|---|---|---|
| margin-left | 1.0 | 6.0 | 1.0 | 1.0 | 3.5 |
定义和用法
margin-top 属性设置元素的上外边距。
注释:允许使用负值。
这个属性对于不可替换的 inline 元素没有效果,比如 <tt> 或者 <span>。
| 默认值: | 0 |
|---|---|
| 继承性: | no |
| 版本: | CSS1 |
| JavaScript 语法: | object.style.marginTop="10px" |
可能的值
| 值 | 描述 |
|---|---|
| auto | 浏览器设置的上外边距。 |
| length | 定义固定的上外边距。默认值是 0。 |
| % | 定义基于父对象总高度的百分比上外边距。 |
| inherit | 规定应该从父元素继承上外边距。 |
相关页面
CSS 教程:CSS 外边距