简体   繁体   English

是否可以排除一个特定div容器的所有CSS样式?

[英]Is it possible to exclude all css styling for one specific div container?

I'm having problems using font-face on my website. 我在网站上使用font-face时遇到问题。 I can get it working when testing it on a html file with it's own styling, but not if I include other style sheets. 我可以使用它自己的样式在html文件上测试它时使用它,但如果我包含其他样式表则不行。

I've tried overriding stles, placing style sheets in different order and so on, but nothing works. 我试过重写stles,以不同的顺序放置样式表等等,但没有任何作用。

So I'm wondering, is it possible to exclude all CSS and only use css from one css file for a specific div container? 所以我想知道,是否可以排除所有CSS并仅使用css从一个css文件中获取特定的div容器?

(Without using iframe ) (不使用iframe

Unfortunately no, it's not possible to just clear or reset the styles for a specific container from the css it's inherited. 不幸的是,不可能只从它继承的css中清除或重置特定容器的样式。 You have to override each style that you want manually. 您必须手动覆盖所需的每种样式。

What you can do is you could namespace your classes and all you'd have to worry about would be element styles that you could define with defaults at the beginning of your style sheet. 你可以做的是你可以命名你的类,所有你必须担心的是你可以在样式表的开头用默认值定义的元素样式。 For example, something like: 例如,类似于:

div,table,span,img,p{
    margin: 0;
    padding: 0;
    border: 0;
    font-weight: normal;
    font-style: normal;
    font-size: 100%;
    line-height: 1;
    font-family: inherit;
    text-align: left;
}

You can of course add !important to ones that you need and add more elements to the list. 您当然可以将!important添加到您需要的那些并向列表中添加更多元素。 If you can't trust or don't know the other styles that are going to be loaded and applied to your page, I find it's best to just start with an empty slate. 如果你不能相信或者不知道将要加载并应用到你的页面的其他样式,我发现最好是从一个空的平板开始。

No, you cannot. 你不能。 There is no such exclusion mechanism in CSS or in HTML. CSS或HTML中没有这样的排除机制。

You real problem is probably solvable, though, but you did not describe it. 你真正的问题可能是可以解决的,但你没有描述它。 You should describe, in a new question, what you want, what you have tried, and how it fails. 您应该在一个新问题中描述您想要什么,您尝试过什么以及它如何失败。 With real code and/or URL. 使用真实的代码和/或URL。

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

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