HTML / CSS:将列表填充重置为默认值

发布于 2024-10-30 01:34:07 字数 267 浏览 1 评论 0 原文

我正在使用 *{margin:0; padding:0;} 这是第一次让我崩溃。 列表填充和边距也为 0,因此缩进丢失。并且我想将它们重置为原始状态,这怎么可能?

我已经尝试过但没有成功:

ul,ol{ 
   margin :auto; /* This Works */
   padding:auto; /* This Not :( */
}

那么我应该如何解决这个问题?

I'm using *{margin:0; padding:0;} and this is the first time that it breaks me in something. List paddings and margins are 0 too, so the indentation is lost. and I would like to reset them to their original state, how is this possible?

I've tried this with no success:

ul,ol{ 
   margin :auto; /* This Works */
   padding:auto; /* This Not :( */
}

So how should I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

苍白女子 2024-11-06 01:34:08

重置的目的是消除由于浏览器默认设置造成的变化。换句话说,没有明确的方法来“取消重置”,因为不同的浏览器可能有不同的默认值。

但是,您可以选择自己的默认值,我认为这就是您在这里尝试做的。

执行此操作的一个好方法是查看浏览器的默认样式表(您应该能够通过搜索找到如何执行此操作)。例如,您可以使用以下 URL 查看 Firefox 默认样式表:resource://gre/res/html.css

The point of a reset is to eliminate variations due to browser defaults. In other words, there is no definitive way to "unreset" because different browsers may have different defaults.

However, you can choose your own default values, and I think that's what you're trying to do here.

A good way to do this is to look at a browser's default stylesheet (you should be able to find how to do this by doing a search). For example, you can see the Firefox default stylesheet with this URL: resource://gre/res/html.css

栩栩如生 2024-11-06 01:34:08

无法恢复默认值,但更改“ol”或“ul”和“li”的填充看起来不错。这对我有用..

ol{
    padding: 0 25px;
}
ol li{
    padding-left: 0px;
}

There is no way to restore default values, but changing padding of 'ol' or 'ul' and 'li' it will look fine. This works for me..

ol{
    padding: 0 25px;
}
ol li{
    padding-left: 0px;
}
小苏打饼 2024-11-06 01:34:08

正如您所看到的,如果您使用下面的代码片段,列表 padding-leftinitial 值为 0。我的观点是关于你的陈述:

我想将它们重置为原始状态

,我试图说明这一点,@jdigital 在他的回答中所说的是 CSS 属性没有原始状态,所有这些属性都是取决于他们的浏览器实现,例如默认浏览器样式表。

ul {
  outline: 1px solid coral;
  list-style: none;
  padding-left: 48px;
}

li {
  outline: 1px solid lightseagreen;
}

ul {
  padding-left: initial;
}
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
<ul>

As you can see if you play with the snippet below, the initial value for list padding-left is 0. My point is regarding your statement:

I would like to reset them to their original state

what I'm trying to illustrate and what @jdigital was kind of saying in his answer is that there is no original state for CSS properties, all of them are dependent on their browser implementation, e.g. default browser stylesheets.

ul {
  outline: 1px solid coral;
  list-style: none;
  padding-left: 48px;
}

li {
  outline: 1px solid lightseagreen;
}

ul {
  padding-left: initial;
}
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
<ul>

咽泪装欢 2024-11-06 01:34:08

重置填充和边距时必须记住,例如 *{padding: 0;边距:0;}ul 标记有一些填充,如 padding-inline-start: default_value;

通过以下这些步骤,您可以摆脱这个 list-style-position: Outside; 问题:

  • 首先找出 padding-inline-start open 的默认值您的浏览器开发人员工具并选择您的 ul 标签。
  • 在“元素”选项卡下方或旁边的“样式”选项卡中(取决于您打开的开发人员工具的分辨率)滚动并从“用户代理样式表”中找到“ul”标签样式,它将看起来像这样 “用户代理
  • 正如您在我的浏览器中看到的 padding-inline-start 样式,其值是 40px。现在记下这个值。
  • 然后转到您最喜欢的代码编辑器,并在其中设置特定 ul 的样式,例如 ul{padding-inline-start: 40px}
  • 不要忘记删除我们在开始时所做的评论是为了在重置边距和填充时查看效果

希望这对您有用。

You have to keep in mind when you reset padding and margin such as *{padding: 0; margin: 0;}. The ul tag have some padding as padding-inline-start: default_value;.

The following these steps you can get rid of this list-style-position: outside; issue :

  • First of all to find out the default value of padding-inline-start open your browser developer tools and select your ul tag.
  • In the styles tab below or aside to the Element tab (depending on the resolution of Developer tools you have opened) scroll and find the ul tag styles from user agent stylesheet it will look like this image of user agent dtyle sheet
  • As you have seen the styling of padding-inline-start in my browser its value is 40px. Now note this value.
  • Then goto your favorite code editor where you are coding and set the style of specific ul such as ul{padding-inline-start: 40px}
  • Don't forget to remove the comment we have make at the start to see the effect while resetting the margin and padding

Hope this will work for you.

旧伤还要旧人安 2024-11-06 01:34:08

revert 就是您正在寻找的内容。它基本上会恢复由您的样式表创建的任何样式,而不是用户代理/浏览器样式表。

ol, ul, li, {
 margin: revert;
 padding: revert; /* Padding is what gives the indentation */ 
} 

参考:

revert is what you are looking for. It will basically revert any styles made BY YOUR STYLESHEET and not the user-agent/browser stylesheet.

ol, ul, li, {
 margin: revert;
 padding: revert; /* Padding is what gives the indentation */ 
} 

Reference:

千寻… 2024-11-06 01:34:08

如果我正确理解了这个问题,您可以尝试添加 !important; ,如下所示:

ul, ol {
   margin : auto;
   padding: auto !important;
}

通常,它会覆盖所有早期的预定义值。

If I understand the question correctly, you could try adding !important; as in the following:

ul, ol {
   margin : auto;
   padding: auto !important;
}

Normally, it overrides all earlier predefined values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文