CSS
CSS 水平对齐(Horizontal Align)
注意:IE5中块元素有一个margin处理BUG。为了使上述例子能工作,在IE5中,需要添加一些额外的代码,实例。
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <style> .container { text-align: center; } .center { margin-left: auto; margin-right: auto; width: 70%; background-color: #b0e0e6; text-align: left; } </style> </head> <body> <div class="container"> <div class="center"> <p>In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.</p> <p>'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.'</p> </div> </div> <p><b>Note:</b> In IE5 there is a margin handling bug for block elements. Block elements are sometimes treated as inline content. This is particularly problematic when it comes to centering. For centering to work in IE5, use the text-align property, like in this example.</p> </body> </html>
运行结果:
点击运行 »