css风格以safari为中心

时间:2009-12-13 19:23:36

标签: html css stylesheet

我正在使用像这样的CSS样式

text-align:center;

它在IE中工作,不适用于Safari ..

任何建议。

感谢,

4 个答案:

答案 0 :(得分:4)

据我所知,中心文本内容没有特定的浏览器/文档类型问题。所以看起来你正试图将其他东西放在文本之外。如果您确实要将块元素居中,请为其添加固定的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>

然而,这在quirks模式的IE中不起作用。只需确保您使用的是strict doctype

答案 1 :(得分:2)

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

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

答案 2 :(得分:1)

Validating your html and css是解决任何渲染问题的第一步(即使在像IE 6这样的软件浏览器中)。

答案 3 :(得分:0)

我明白了我的代码:

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

现在正在运作 感谢所有试图帮助我的人