css样式定心在Safari

问题描述:

我使用的CSS样式这样css样式定心在Safari

text-align:center; 

它在IE工作,不与野生动物园工作..

任何建议。

谢谢,

这取决于你想要的风格。您可能试图将块级元素居中放置,如DIV或UL。在这种情况下,你使用中心

div { 
    margin-left:auto; 
    margin-right:auto; 
    padding-left:<some fixed size>; 
    padding-right:<some fixed size>; 
    width:<some fixed size>; 
} 

Validating your html and css是第一步,以找出任何渲染问题(即使在craptastic浏览器如IE 6)。

+0

*轻笑* craptastic。 – CodeMonkey 2009-12-13 20:27:08

居中的文字内容据我所知没有具体的浏览器/文档类型的问题。所以它看起来像你试图集中别的东西而不是文本。如果您确实想要将块元素居中,请给它一个固定的width(以像素为单位),并在其上应用margin: 0 auto;

下面是一个SSCCE

<!doctype html> 
<html lang="en"> 
    <head> 
     <title>SO question 1897444</title> 
     <style> 
      #center { 
       margin: 0 auto; /* top and bottom 0, left and right expanding. */ 
       width: 300px; /* Required to have a reference point to center. */ 
       border: 1px solid black; /* Not required, just presentational. */ 
      } 
     </style> 
    </head> 
    <body> 
     <div id="center">Centered block element</div> 
    </body> 
</html> 

不过,这不会怪癖模式在IE浏览器。只要确保你使用的是strict doctype即可。

我得到了我所做的代码点:

width: 190px; 
padding-left:23px; 
height: auto; 
text-align: left; 
line-height: 18px; 

和现在 感谢工作都在努力帮助我