覆盖CSS文件中的定义 [英] override definition in css file

查看:29
本文介绍了覆盖CSS文件中的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个css文件,该文件定义了所有< p> 标签的样式.

I have a css file that defines style for all <p> tags.

像这样

 p { ......... }

如何在包含具有默认样式的样式表的页面中编写< p> ?

How can I write a <p> in a page where the stylesheet is included that has default styling?

推荐答案

没有简单的方法可以做到这一点.

There's no easy way to do this.

尽管有一些通用技巧可以模拟这种行为.最好使用哪种方法取决于覆盖区域的复杂程度以及您执行此操作的频率.

There a some common tricks to simulate that behavior though. The best one to use would vary based on how complex the overridden region is, and how often you want to do this.

方法1(用于简单替代):

在语句中添加一个类似于清除默认样式的类定义(例如,在 http://www.wordpress.darfuria.com/blog/clear-css-defaults ).您可能需要仔细安排声明,以防止普通"样式优先.

Add an extra class definition in the statement similar to the one where you clear the default styling (such as is discussed at http://www.wordpress.darfuria.com/blog/clear-css-defaults). You might have to arrange the declarations carefully to prevent the 'normal' style from taking precedence.

.override {/*Your default style overrides, color: white;
 margin: 0; background:none; etc */}


<p class="override">foo</p>

方法2(笨重,但适用于复杂区域)

使用iframe从托管在您网站其他位置的单独.html文件提取整个区域.iframe内的内容尊重框架内页面的CSS,通常会忽略周围页面的CSS.

Use an iframe to pull the whole region from a separate .html file hosted elsewhere on your site. The content inside iframes respects the CSS of the page inside the frame, and generally ignores the CSS from the surrounding page.

方法3(适用于一键式覆盖):

使用内联样式,如其他人在此处所述.

Use inline styles, as others have described here.

不是真正的方法,但可能是最正确的方法

也许也不是您想听到的

重新考虑您如何安排课程.

Re-think your how you've arranged your classes.

例如:

如果重写的< p> 在某种程度上是特殊的,则可能值得使用它自己的类来描述其目的.< p class ='override'> 不会帮助您在完成设计后查看您的设计的人,因为它不会告诉他们被覆盖的文字是什么意思或原因它的样式就是这样.

If the overridden <p> is special in some way, it probably deserves it's own class that describes what it's purpose is. <p class='override'> doesn't help people who will be looking at your design after you're done, since it doesn't tell them what the overridden text is for or why it's styled that way.

替代项是否在特定区域中出现?如果是这样,它们可能更适合 div.left_nav p {/* styles */} 之类的样式定义.

Are the overrides coming in a specific region? If so, them a style definition like div.left_nav p {/*styles*/} might be a better fit.

最后,您的默认< p> 样式不是真的默认样式吗?也许是顺序更宽松的p样式,稍后还会有其他 p.foo p.bar 定义.

Lastly, Is your default <p> styling not really default? Maybe a more loosely specified p style might be in order, with additional p.foo and p.bar definitions later on.

这不能解决您眼前的问题,但是在您开始下一个项目之前可能值得一试.

This doesn't fix your immediate problem, but it might be worth chewing on before you start your next project.

这篇关于覆盖CSS文件中的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆