当前位置:编程学习 > C#/ASP.NET >>

让整个页面居中

<body style="margin:auto;padding:auto;margin:0 auto;">    貌似不行

请各位高手指教

原代码~~谢谢 --------------------编程问答-------------------- <body>
<div style="width:100%;text-align:center;">

</div>
</body>

嵌套一个div试试 --------------------编程问答-------------------- <body style="margin:0 auto;text-align:center;">  --------------------编程问答-------------------- <style>
 body{
   margin:0px auto;
}
</style>
试试 --------------------编程问答-------------------- 不对

我用的是层开发的     --------------------编程问答--------------------  * {  margin:0px auto 0px auto;}   /*全局*/
如果有样式表就写在样式表中 --------------------编程问答-------------------- 我同意楼上的 --------------------编程问答-------------------- 还是没居中啊~~~·。。。。 --------------------编程问答-------------------- 刚试了一下。。。我刚给你的那个只在IE下管用。。

这样写:

<style type="text/css">
   body {margin:0px;padding:0px;text-align:center; }
   body > div {text-align:center; margin-right:auto; margin-left:auto;} 
</style>


<body>中放一个<div> --------------------编程问答--------------------
引用 8 楼 porschev 的回复:
刚试了一下。。。我刚给你的那个只在IE下管用。。

这样写:
CSS code

<style type="text/css">
   body {margin:0px;padding:0px;text-align:center; }
   body > div {text-align:center; margin-right:auto; margin-left:auto;} 
</st……




奇怪  我这还是不行啊 --------------------编程问答-------------------- 你用单独的html试试看,如果可以就说明是你的样式表被某样式重用或覆盖使用……
一楼的好像是可以的…… --------------------编程问答-------------------- HTML头部要加DOCTYPE声明,不加就不起作用,加了自然就居中了。 --------------------编程问答--------------------

<body style="margin-left:auto;margin-right:auto">

这个你试试,应该能行的,我平时都这么做 --------------------编程问答-------------------- 要用margin:0 auto的前提是必须有设置宽和高,width你得定一个width,height可以auto。

--------------------编程问答-------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



body  
{
width:1002px;
margin:0 auto;
font-size:12px;
font-family:Arial;
color:#44473e;
}
--------------------编程问答-------------------- <body>
<center>
//这里放网页代码
</center>
</body>

==================
这个绝对行,我一直再用。 --------------------编程问答-------------------- 我也不知道我这个方法到底科不科学;反正我是一直这么用的;首先把这个大的DIV宽给定了;如下:
.div_style
{
  width:960px;
  margin-left:auto;
  margin-right:auto;
} --------------------编程问答-------------------- 还居中不了。。?

不能够啊。。。

是这么放的吗?
<body>
<div>
----这里是其它----
<div>
</body> --------------------编程问答-------------------- 将所有要居中的内容放到<center></center>之间 --------------------编程问答-------------------- --------------------编程问答-------------------- <body style="margin:0 auto;">或是<body align="center"> --------------------编程问答--------------------
引用 15 楼 zcxverygood123456 的回复:
<body>
<center>
//这里放网页代码
</center>
</body>

==================
这个绝对行,我一直再用。
我就是这样写的.不过这样并不怎么好吧.唉...
正在从table结构到DIV+CSS下来.悲剧的我 --------------------编程问答--------------------
引用 3 楼 ihandler 的回复:
<style>
 body{
  margin:0px auto;
}
</style>


mark............. --------------------编程问答-------------------- 你要是用table 的话, 只需要给 table 设置“  style="margin-left:auto; margin-right:auto"” 就行啦!body 不用管的。。  --------------------编程问答--------------------
引用 12 楼 kc0001x 的回复:
HTML code

<body style="margin-left:auto;margin-right:auto">


这个你试试,应该能行的,我平时都这么做

我平时也这样做 --------------------编程问答-------------------- 如果用css不行,直接用center标签包裹整个body! --------------------编程问答-------------------- 把margin:auto放在层样式里面试试,我经常放在层的样式里面,可以剧中,再看看层的WIDTH有没有设置,如果不设置,没有效果的 --------------------编程问答--------------------  style="margin-left:auto; margin-right:auto"
这个办法好使! --------------------编程问答-------------------- body{
        margin: 0px;
padding:0px;
text-align:center;
}
#container{
position:relative;
margin:0px auto 0px auto;
width:960px;
text-align:left;
}//这个是div 的样式。在body里面加一个div, id为container 就可以了 --------------------编程问答-------------------- 最好把你整体的代码放上来。。 --------------------编程问答-------------------- 先设置*{margin:0;padding:0;}
试试
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,