CSS - 由于 * 定义无法覆盖 P.class [英] CSS - Cannot override P.class because of * definition

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

问题描述

我有一个使用 2 个 css 的网站:一个是全局的,特定于一页的.
默认情况下,我想为所有内容设置字体类型和大小,并根据我在某些页面上的需要进行调整.

I have a site using 2 css : one global, one page specific.
By default, I want to set a font type and size for everything, and adjust it depending on my needs on some pages.

所以我有:

global.css

* {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}

html {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    margin: 0px;
}

p {
    text-align:justify;
    margin:0px;
    margin-bottom:10px;
}

a:link {
    color: #993300;
    text-decoration: none;
}

a:visited {
    color:#993300;
    text-decoration: none;
}

a:hover {
    color: #FF0000;
    text-decoration: underline overline;
}

news.css

div.news{
    width: 100%;
}

.news p.reminder {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: #848484;
    margin:0px;
    margin-bottom:20px;
    text-align: center;
    position: relative;
    top: -10px;
    text-transform: uppercase;
}
.news p.reminder a:link, .news p.reminder a:visited {
    color: #848484;
}
.news p.reminder a:hover {
}

HTML 文件

       <HTML>
          <HEAD>
             <TITLE>the title</TITLE>

              <LINK href="global.css" rel="stylesheet" type="text/css">
              <LINK href="news.css" rel="stylesheet" type="text/css">
           </HEAD>
           <BODY>
              <DIV class="news"> 
                    <P class="reminder"> 
                        <A href="some_url">some text</A> 
                    </P>
                </DIV>
            </BODY>
        </HTML>

出于某种原因,我没有看到,部分:

For a reason I don't see, the part :

.news p.reminder {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;

不考虑.
如果我从 global.css 中删除 * 定义,就可以了.但如果我保留它,那部分不会覆盖它.

is not taken into account.
If I remove the * definition from the global.css, it's OK. But if I keep it, that part does not override it.

我该怎么做才能完成这项工作?

How may I do to make this work ?

推荐答案

你看不到它的原因是,虽然段落确实采用了你想要的样式,但 * 选择器匹配<A href="some_url"> 并及时将它们改回来.

The reason you don't see it is because, while the paragraph does take on the styles you want, the * selector matches <A href="some_url"> and promptly changes them back.

您也可以修改选择器以匹配 a 元素,但我会在 body 而不是 * 上设置字体样式

You could modify the selector to match the a element too, but I'd set the font styling on the body instead of *

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

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