DIV居中、紧靠上边缘、页面去掉横向滚动条(附代码)

回复
头像
Mia2014
帖子: 1805
注册时间: 周三 12月 25, 2013 8:24 pm

DIV居中、紧靠上边缘、页面去掉横向滚动条(附代码)

帖子 Mia2014 » 周日 3月 09, 2014 11:29 pm

1)DIV居中,示例如下:
width: 970px;
margin: 0 auto 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */

2)紧靠上边缘:
我在页面开始代码加了几行php代码<?php code ?>。后来移到下面就去掉那个缝隙了。因为这些代码会在页面解析成一些内容。

3)页面去掉横向滚动条。这个让我费了很多脑筋。因为我不想去掉那个100%宽的,position还要保持absolute的DIV。在IE 8、IE 9里总是有个滚动条。后来证明很容易:在body里定义border、padding、margin、left都为0。我漏写了left就折磨了我几天。

CSS代码:
<style type="text/css">
body {
border:0;
padding:0;
margin:0;
left:0;
font-family:Verdana, Arial;
}

.container {
width: 970px;
margin: 0 auto 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
}
</style>

头像
Mia2014
帖子: 1805
注册时间: 周三 12月 25, 2013 8:24 pm

Re: DIV居中、紧靠上边缘、页面去掉横向滚动条(附代码)

帖子 Mia2014 » 周日 3月 09, 2014 11:29 pm

效果看这里:
http://coolder.com

回复