0

我是 CSS 新手,我接管了某人的 CSS 代码:

.. CSS Reset .. ul, ol, li .. {
   ..
   margin: 0;
   padding: 0;
   ..
}

但是,将填充设置为 0 会有效地禁用自动列表项缩进,但我想要缩进,所以我写道:

<ul style="padding: 10;">
    <li style="padding: 10;">
        <ul style="padding: 10;">
            <li  style="padding: 10;">123</li>
        </ul>
    </li>
</ul>

padding: 10没有任何效果,浏览器仍然显示没有填充,因此没有缩进。

如何使自动缩进恢复原状?

4

3 回答 3

1

朋友,填充值是 10px 而不是 10。

 <li  style="padding: 10;">123</li>

应该

 <li  style="padding: 10px;">123</li>

干杯,

于 2013-10-07T02:22:25.637 回答
0

If you have to work with someone else’s CSS that uses CSS Reset, then you simply have to style everything on your own. So if you want a list to have some indents, you need to create them yourself, and you probably need to use a class or id attribute on the list elements that you want to have affected.

In general, yhere is no way to get the browser’s default styling back when you have overridden it with CSS Reset. You can only explicitly override the override. Assuming you have <ul class=foo> so that you want that list and all ul lists inside it to have indentation, you can set

ul#foo, ul#foo ul { padding-left: 40px }

This establishes the “expected” default indentation as per HTML5 CR. This corresponds reasonably well to typical browser defaults, but actual defaults may still differ.

If you do not wish to establish something that is expected to match defaults but some reasonable indentation, you can use the em unit, which adapts to font size, and use a relatively small value:

ul#foo, ul#foo ul { padding-left: 1.3em }
于 2013-10-07T05:45:16.920 回答
0

您从用户代理样式表或也称为浏览器样式表中获得填充。您的用户样式表会覆盖它。您需要从您的 css 样式规则中删除 ol、ul、li 选择器,该规则告诉这些元素它们没有应用填充或边距。这也是我第一次看到padding: auto这真的可能吗?

于 2013-10-07T02:05:21.653 回答