margintop

阅读:36      收藏:0      [点我收藏+]

Style marginTop 属性


定义和用法

marginTop 属性设置或返回元素的上外边距。

语法

设置 marginTop 属性:

Object.style.marginTop="%|length|auto|inherit"

返回 marginTop 属性:

Object.style.marginTop

描述
% 定义基于父元素宽度的百分比上外边距。
length 使用 px、cm 等单位定义上外边距的宽度。
auto 浏览器设定的上外边距。
inherit 上外边距从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 marginTop 属性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


提示和注释

margin 属性和 padding 属性都是在元素周围插入空间。然而,不同的是,margin 将围绕边框外面插入空间,padding 将在元素边框内插入空间。


实例

更改 div 元素的上外边距:

<html>
<head>
<style type="text/css">
#ex1
{
border: 1px solid #FF0000;
}
</style>
<script>
function displayResult()
{
document.getElementById("ex1").style.marginTop="100px";
}
</script>
</head>
<body>

<div id="ex1">This is some text.</div>
<br>
<button type="button" onclick="displayResult()">Change top margin</button>

</body>
</html>

关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!