我们可以将图像设置为背景图像<div>
like:
<style>
#test {
background-image: url(./images/grad.gif);
background-repeat: no-repeat;
background-position: center center;
width:80%;
margin-left:10%;
height:200px;
background-color:blue;
}
</style>
<div id="test"></div>
我需要在房间的中央放一张桌子<div>
水平和垂直。有没有使用跨浏览器的解决方案CSS
?
居中是 CSS 中最大的问题之一。然而,存在一些技巧:
要使表格水平居中,您可以将左右边距设置为自动:
<style>
#test {
width:100%;
height:100%;
}
table {
margin: 0 auto; /* or margin: 0 auto 0 auto */
}
</style>
要使其垂直居中,唯一的方法是使用 javascript:
var tableMarginTop = Math.round( (testHeight - tableHeight) / 2 );
$('table').css('margin-top', tableMarginTop) # with jQuery
$$('table')[0].setStyle('margin-top', tableMarginTop) # with Mootools
No vertical-align:middle
这是可能的,因为表是一个块而不是内联元素。
Edit
这是一个总结 CSS 居中解决方案的网站:http://howtocenterincss.com/ http://howtocenterincss.com/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)