html小白一个。遇到的代码想将它居中,然后尝试了align="center"和
都没有效果。代码精简后是这样的: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>待居中</title>
<style type="text/css">
.导航栏 {
position: absolute;
width: 1260px;
top: 61px;
height: 33px;
left: 12px;
font-size: 24px;
background-color: #128BDA;
color: #FFF;
font-family: "Arial Black", Gadget, sans-serif;
font-weight: bold;
z-index: 100;
}
.gywm {
position: absolute;
left: 12px;
top: 800px;
width: 474px;
height: 93px;
}
.hzzd {
position: absolute;
left: 529px;
top: 800px;
width: 764px;
height: 121px;
}
.
body {
background-image: url();
align="center";
}
.back {
position: absolute;
left: 10;
top: 0px;
z-index: 0;
}
</style>
</head>
<body>
<div>
<div class="back"><img src="images/back.jpg" width="1280" height="909" border="0" align="absmiddle" /></div>
<div class="hzzd">
<p>合作站点</p>
</div>
<div class="gywm">
<h4>关于我们</h4>
</div>
<p align="left"> </p>
<p align="left"> </p>
<div class="导航栏"><strong>首页</strong></div>
<div class="导航栏">
<table width="1260" border="0" align="center">
<tr>
<td width="115" scope="row"><a href="index.php" target="_blank"style="color:#FFFBF0">首页</a></td>
<td width="209">1</td>
<td width="189">2</td> </tr>
</body>
</html>
额。。为什么上传之后变成这个样子的了。。
楼主,align="center"是标签属性,设置或获取表格排列。如div,table等标签可以快速使用。但是有许多标签是不支持这个属性,同样也存在兼容问题
在你的页面上放一个div
<div id="center">
你的网页放在里面
</div>
添加如下样式
body {TEXT-ALIGN: center;}
#center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; }
.box{maring:0 auto;}这样它就居中了!
思路就是在body中加一个div来放你网页要居中的内容,然后将这个div在body中居中,要使这个div在body中居中就必须要给这个div指定宽度,然后再加上margin:auto样式就可以了,代码如下:
<body>
<div style="MARGIN: auto; width:100px;">{这里放你网页的内容}</div>
</body>
希望对你有帮助
<div style="margin:0px auto;width:900px">你body里面原来的内容,一定要加宽度,要不设置margin无效</div>
你直接用
包起来不就可以了么。。。text-align: center;文字居中
vertical-align: middle;垂直居中
margin: 0 auto;也可以居中
LZ到底想要什么居中效果?
align="center";css有这个吗?