StupidBeauty
Read times:637Posted at:Sat Jul 6 05:41:14 2013
- no title specified

转载完美解决CSS网页水平居中

网页水平居中,就让页面的主要内容元素的margin-left和margin-right都为auto,并且 要明确指定宽度。

http://www.php100.com/html/webkaifa/DIV_CSS/2010/0826/5303.html

亮点

使用自动外边距实现居中

  CSS中首选的让元素水平居中的方法就是使用margin属性—将元素的margin-left和margin-right属性设置为auto 即可。在实际使用中,我们可以为这些需要居中的元素创建一个起容器作用的div。需要特别注意的一点就是,必须为该容器指定宽度:

  div#container{ margin-left:auto; margin-right:auto; width:168px; }

  在大多数主流浏览器中,这种方法都非常有效,即使是Windows平台上的IE6,在其标准兼容模式(compliancemode)下也能够 正常显示。但不幸的是,在更低版本的IE中,这种设置却并不能实现居中效果。所以若想在实际项目中使用这种方法,那么就要确保用户的IE浏览器版本不低于 6.0。

  尽管在支持上不尽如人意,但大多数设计师都建议尽可能地使用这种方法。该方法也被认为是在各种用CSS实现元素水平居中方法中最正确、最合理的一种。

未知美人

Your opinions
Posted at:Thu Feb 28 04:54:52 2019沉盥洗988217
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4