简体   繁体   English

如何不将重置CSS文件继承到特定的div?

[英]how not to inherit reset css file to a particular div?

I have a page with 2 divs and reset css is added to remove all the browser defaults added to the page initially. 我有一个包含2个div的页面,并添加了重置CSS,以删除最初添加到该页面的所有浏览器默认设置。 Inside the 2nd div i have certain Ul and li which uses browser paddings. 在第二个div内部,我有一些使用浏览器填充的Ul和li。 The problem is i dont want reset css to inherited to the 2nd div. 问题是我不想重置CSS继承到第二个div。 2nd div remaining elements should not be resetted using reset css. 不应使用重置CSS重置2div剩余元素。 Can you please tell how to prevent reset css being inherited to 2nd div. 您能告诉我们如何防止将重置CSS继承到第二个div吗? Thanks !!! 谢谢 !!!

     <style>
        html, body, div, span, applet, object, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, 
        abbr,acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small,
        strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, fieldset, form, label, 
    legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details,
     embed, figure,ul,li,ol,figcaption, footer, header, hgroup, menu, nav, output, ruby, 
      section, summary, time, mark, audio, video {
  margin: 0;
 padding: 0;
 border: 0;
 font-size: 100%;
 font: inherit;
 vertical-align: baseline;
        }
      </style>
 <div>
   <ul><li>Reset CSs should be inherited</li></ul>

 </div>
 <div>
   <ul>
      <li>Default browser padding to be added without reset css</li>
    </ul>
 </div>

Use classes like, 使用classes一样,

CSS 的CSS

.reset-css{
   /** properties for reset */
}

HTML 的HTML

<div class="reset-css">
   <ul><li>Reset CSs should be inherited</li></ul>
</div>

Learn Css and Learn HTML 学习CSS学习HTML

The purpose of the global reset is to reset everything. 全局重置的目的是重置所有内容。 Applying the reset on some elements but omitting others will create inconsistencies between different browsers and devices. 在某些元素上应用重置,而忽略其他元素,则会在不同的浏览器和设备之间造成不一致。

The most symantic approach is to do as you've already done - apply a global reset, but then create a new class that will apply a new style over whatever element you choose: 最对称的方法是按已做的方式进行操作-应用全局重置,然后创建一个新类,该新类将对您选择的任何元素应用新样式:

.new-class {
    // styles
}

In your case, re-create the 'old style' that was there before the reset was created - this will insure that all browsers will render the correct styling. 在您的情况下,请重新创建创建重设之前的“旧样式”-这样可以确保所有浏览器都能呈现正确的样式。

Read more about CSS resets: Purpose of the CSS reset 阅读有关CSS重置的更多信息:CSS重置的目的

Just put a style in element. 只需在元素中添加样式即可。 Either from id, class or inline style. 从id,class或inline样式中选择。 Just make sure that reset.css is first to call for the new styles to be used. 只需确保reset.css首先调用要使用的新样式即可。 The style hierarchy goes like this. 样式层次结构是这样的。

external stylesheet
class (class="classname")
id (id="elem-id")
inline (style="height: 100px;")

then with !important 然后用!important

external - stylesheet with !important
class - with !important
id - with !important
inline - with !important

So in your case, it's your choice to have an id, class, or put an inline style. 因此,在您的情况下,可以选择具有id,类或内联样式。

<div>
   <ul><li>Reset CSs should be inherited</li></ul>

 </div>
 <div style="background-color: red; font-size: 12px">
   <ul>
      <li>Default browser padding to be added without reset css</li>
    </ul>
 </div>

the inline style will be the priority. 内联样式将是优先事项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM