请问CSS中text-align:center不能居中?

CSS中text-align:center不能居中


大话西游666
浏览 5409回答 4
4回答

神不在的星期二

text-align:center 与 <CENTER>您可能会认为&nbsp;text-align:center 与 <CENTER> 元素的作用一样,但实际上二者大不相同。<CENTER> 不仅影响文本,还会把整个元素居中。text-align&nbsp;不会控制元素的对齐,而只影响内部内容。元素本身不会从一段移到另一端,只是其中的文本受影响。

至尊宝的传说

<div style="text-align:center">adsfasdfasdf<p>asdfasdf</p><div style="display:block; width:200px; background-color:yellow" >div1</div></div><div><center>adsfasdfasdf<p>asdfasdf</p><div style="display:block; width:200px; background-color:yellow" >div2</div></center></div><center>是将所有被包含的元素都居中显示,而text-align:center只是将元素下面的内联元素居中显示。例子就是黄色div是block块元素,用text-align:center没用,居左; 下面的用<center>会居中。css中可用align:center : 和<center>标签效果一致。<div align="center"> asdasdfljsadfj<div style="display:block; width:200px; background-color:yellow" >balablkaa</div></div>另外块元素通常用margin:0 auto实现居中。

慕斯709654

因为你footer没有居中啊o(╯□╰)o。你应该在CSS里面加这条属性:#footer {margin-left: auto;margin-right: auto;}如果还不行的话可以给footer设置一个具体的宽度-。-然后margin: auto;还有一种方法是给footer一个和上方页面等宽的宽度也行。
打开App,查看更多内容
随时随地看视频慕课网APP