将css应用于特定的<a> tag

时间:2015-07-13 16:55:08

标签: html css

I apply css to a specific tag, but it's not working. The following is my code: HTML:

<div id="content">
        <div class="fixedwidth">
            <p><span class="date">2 April 2014 Last update at 15:23</p>
            <h1>Norwich 'explosion': Two people dead</h1>
            <img class="headlineimg" src="pictures/headline.jpg" />
            <div class="newsitem">
                <p>Two people have died in a suspected explosion at an industrial estate in Norwich.</p>
                <p><a href="">Protest shuts Heathrow Airport runway</a></p>
                <p><a href="">Harman 'happy to be overruled' on cuts</a></p>
                <p><a href="">Get poor pupils 'into schools early'</a></p>
                <p><a href="">Bird flu confirmed at Lancashire farm</a></p>

            </div>
        </div>
    </div>

css:

.newsitem a{
            color:#1F4F82
            text-decoration:none;
        }

.newsitem a:hover{
            text-decoration:underline;
        }

Can anyone tell me what is wrong with my code? Thanks.

2 个答案:

答案 0 :(得分:4)

在您的第一个声明中,您在设置颜色

后错过了分号

答案 1 :(得分:1)

在那里工作很好。我认为你的代码或者可能存在冲突,你做得不对。

可能解决这个问题的方法 一世。右键单击元素并单击inspect元素,然后尝试使用屏幕右侧的css选择器框对其进行编辑 II。将!important添加到您的代码中,如下所示:

.newsitem a{
            color:#000000 !important;
            text-decoration:none;
        }

.newsitem a:hover{
            text-decoration:none !important;
        }

希望它有效。