html+css中我写了text-align:center;可是为什么文段还是不居中

如上图所示。
还可以百度搜索“YJY个人博客”点第一个进到my网页,上面这个图在网页最底下

因为你footer没有居中啊o(╯□╰)o。
你应该在CSS里面加这条属性:
#footer {
margin-left: auto;
margin-right: auto;

}
如果还不行的话可以给footer设置一个具体的宽度-。-然后margin: auto;
还有一种方法是给footer一个和上方页面等宽的宽度也行。追问

加了 ,还是不行啊

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-14
text-align:center;在IE高级版本和非IE浏览器中只是让元素内内容居中显示,如果要整理居中需要用到margin:auto。
比如:
<style>
.abc{clear:both;width:600px;height:300px;border:1px solid red;text-align:center;}
</style>
<div class="abc">这里写文字或其他内容标签</div>
在非IE浏览器中,上面的实例只是里面的文字居中了

<style>
.abc{clear:both;width:600px;height:300px;border:1px solid red;text-align:center;margin:auto;}
</style>
<div class="abc">这里写文字或其他内容标签</div>
上面的实例加了margin:auto,实现整体居中,兼容全部浏览器。
第2个回答  2014-07-21
要加
line-height:外面那个div的高度;追问

    没太懂,求详解

追答

就是给套着““YJY个人博客”这几个字的的那个div的css那里添加一行设置一下他的line-height:属性,属性的值等于这个div的高度

追问

高度 和 居不居中 有关系吗?

追答

有啊,发个例子给你看看吧

<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style>
#div1
{
width:200px;
height:200px;
background: #ccc;
margin:10px;
text-align: center;
}
#div2
{
width:200px;
height:200px;
background: #abcdef;
margin:10px;
text-align: center;
line-height: 200px;
}
</style>
</head>
<body>
<div id="div1">
<span>文本一(没有line-height)</span>
</div>
<div id="div2">
<span>文本二(有line-height)</span>
</div>
</body>
</html>