列表样式 CSS 覆盖恢复为默认值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9636132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 03:13:33  来源:igfitidea点击:

List-Style CSS override back to default

css

提问by Blynn

I want to turn this css element back to the default setting and I can't figure out how to override these list-style css elements. They are on another style sheet that I can't alter but I'm linking to. Please help if you know how.

我想将此 css 元素恢复为默认设置,但我不知道如何覆盖这些列表样式的 css 元素。它们位于另一个我无法更改但我正在链接的样式表上。如果你知道怎么做,请帮忙。

ol li {
  list-style: decimal;
}
ol {
  list-style: decimal outside;
}

回答by Alexander Pavlov

Use !important, e.g.:

使用!important,例如:

ol li {
  list-style: inherit !important;
}

ol {
  list-style: inherit !important;
}

回答by Jeff Escalante

It's not advisable to use !important, ever really. You can do what chipcullen said above by adding a container or if you want a simple override that will work no matter what, you can do something like this:

不建议使用 !important,真的。你可以通过添加一个容器来完成上面的chipcullen所说的,或者如果你想要一个无论如何都可以工作的简单覆盖,你可以做这样的事情:

body ol {
  margin: 1em 0;
  padding: 0 0 0 40px;
}

body ol li {
  list-style-type: decimal;
}

The values I put inside there should reset to the browser defaults, and are taken from normalize.css.

我放在里面的值应该重置为浏览器默认值,并取自normalize.css

回答by Jonny White

You may need:

你可能需要:

ol li { display: list-item; }

回答by chipcullen

I would go about trying to use specificity to set the li styling to whatever you want. Do you have a parent element that you could hook onto? Like, if it was a div with the class container, do something like:

我会尝试使用特异性将 li 样式设置为您想要的任何样式。你有一个可以挂钩的父元素吗?就像,如果它是带有类容器的 div,请执行以下操作:

.container ol li {
  /* whatever you want */
 }