yuanjiechen
例如:.html文件代码如下,
<html>
<head>
<title>居中DIV</title>
</head>
<body>
 <div id="mainDiv>
居中的div
</div>
</body>
</html>
则实现居中的方法CSS代码为
第一种方法:
body
{
text-align:center ;
background-color:#ccc;
min-width:780px;
}
#mainDiv
 {
 width:760px;
 border:1px solid white;
 margin:0 auto
}
 第二种
负空白边定位法实现的CSS代码为
body {
text-align:center
 background-color:#ccc;
 min-width:780px;
 }
#mainDiv
 {
width:760px;
margin-left:-380px;
 left:%50;
 positive:relative;
border:1px solid white
}
好了,有人会问为什么要使用“min-width”属性来定义body的最小宽度呢?,而且其最小宽度要大于或等于div的宽度。
如果不怎样,可能会出现页面的内容被挤出浏览器的可视区域,具体这是为什么这个是浏览器的问题,各种浏览器对CSS
 的支持有少许不同。留着大家自己去研究吧!

分类:

技术点:

相关文章:

  • 2021-12-29
  • 2022-12-23
  • 2021-12-31
  • 2021-11-30
  • 2022-12-23
  • 2021-11-05
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2021-12-09
  • 2021-12-31
  • 2021-11-21
  • 2021-06-15
相关资源
相似解决方案