什么是默认列表样式(CSS)?

问题描述 投票:80回答:7

在我的网站上,我使用reset.css。它将这个添加到列表样式:

ol, ul {
    list-style: none outside none;
}
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
    background: none repeat scroll 0 0 transparent;
    border: 0 none;
    font-size: 100%;
    margin: 0;
    outline: 0 none;
    padding: 0;
    vertical-align: baseline;
}

问题是所有列表样式都设置为NONE。我想仅恢复网站子页面上所有列表的原始列表样式(默认)(.my_container中的所有列表)。

当我尝试设置像list-style-typeinherit这样的东西时,不会继承浏览器的默认样式,只是为了这个CSS属性。

有没有办法在不修改reset.css的情况下为某些属性继承原始浏览器的样式?

html css list html-lists
7个回答
124
投票

我曾经设置这个CSS来删除重置:

ul { 
   list-style-type: disc; 
   list-style-position: inside; 
}
ol { 
   list-style-type: decimal; 
   list-style-position: inside; 
}
ul ul, ol ul { 
   list-style-type: circle; 
   list-style-position: inside; 
   margin-left: 15px; 
}
ol ol, ul ol { 
   list-style-type: lower-latin; 
   list-style-position: inside; 
   margin-left: 15px; 
}

编辑:具体课程......


30
投票

我认为这实际上是你正在寻找的:

.my_container ul
{
    list-style: initial;
    margin: initial;
    padding: 0 0 0 40px;
}

.my_container li
{
    display: list-item;
}

9
投票

http://www.w3schools.com/tags/tag_ul.asp

ul { 
    display: block;
    list-style-type: disc;
    margin-top: 1em;
    margin-bottom: 1em;
    margin-left: 0;
    margin-right: 0;
    padding-left: 40px;
}

9
投票

根据文档,大多数浏览器将使用以下默认值显示<ul><ol><li>元素:

ULOL标记的默认CSS设置:

ul, ol { 
    display: block;
    list-style: disc outside none;
    margin: 1em 0;
    padding: 0 0 0 40px;
}
ol { 
    list-style-type: decimal;
}

LI标签的默认CSS设置:

li { 
    display: list-item;
}

样式嵌套列表项:

ul ul, ol ul {
    list-style-type: circle;
    margin-left: 15px; 
}
ol ol, ul ol { 
    list-style-type: lower-latin;
    margin-left: 15px; 
}

注意:如果我们将上述样式与类一起使用,结果将是完美的。另请参阅不同的List-Item标记。


4
投票

你不能。每当应用任何样式表为元素分配属性时,对于该元素的任何实例,都无法获得浏览器默认值。

reset.css的(有争议的)想法是摆脱浏览器默认设置,以便您可以从干净的桌面开始自己的样式。没有版本的reset.css完全做到这一点,但是在他们这样做的范围内,使用reset.css的作者应该完全定义渲染。


2
投票

您正在重置第二个css块中所有元素的边距。默认保证金是40px - 这应该可以解决问题:

.my_container ul {list-style:disc outside none; margin-left:40px;}

0
投票

未来的答案:CSS 4可能包含revert关键字,它将属性从用户或用户代理样式表[source]恢复为其值。在编写本文时,只有Safari支持这一点 - check here以获取有关浏览器支持的更新。

在您的情况下,您将使用:

.my_container ol, .my_container ul {
    list-style: revert;
}

另请参阅this other answer以及更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.