Internal Stylesheet NOT overriding External stylesheet?

我的未来我决定 提交于 2020-01-05 05:47:09

问题


I'm trying to add some custom styles to a few tags but finding it difficult to override the external CSS file. Adding styles inline seems to work fine, but using an internal page stylesheet is not working out. Tags are still using external styles.

For example, this is not working

<link rel="stylesheet" type="text/css" href="styles.css" />

<style type="text/css">

    h1 {
        font-size:36px;
    }

  </style>

I even tried creating a custom style

<style type="text/css">

    h1.heading {
            font-size:36px;
        }

 </style>

And there is no change.

This JSFiddle demonstrates the problem.


回答1:


I see at least one issue. If you're interested in finding out what happened to this: <h1><a href="#">xx</a></h1>

Here's your problem. In your external CSS:

#header h1 a {
    display: block;
    width: 273px;
    height: 51px;
    background: url(images/cap-logo.png);
    text-indent: -9999px;
}

The use of the ID is the most specific version of h1 with an a inline child to a #header element, so this is what gets used. As you can probably tell, this is moving the header outside the visible area.

There's a couple ways to bring this back on the screen. The easiest way is to change the <h1> to a span with an id:

<span id="big-x"><a href="#">xx</a></span>

And then it's relatively trival to do what you need with this element.

Other options are to change the CSS rule, or be at least that specific in your inline rule. I did that in an updated fiddle: http://jsfiddle.net/p2M7r/1/

#header h1 a {
    font-size:96px;
    text-indent: 0;
}


来源:https://stackoverflow.com/questions/18703587/internal-stylesheet-not-overriding-external-stylesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!