html - 赋予 CSS 属性最高优先级

标签 html css

我想给予 <h1> 最高优先级.在我的示例中,我想要 <h1> 的背景-要显示的元素,而不是为 <a> 指定的内容-元素。

h1{
  background-color:blue1!important
} 

但它在下面的上下文中不起作用:

<!DOCTYPE html>
<html>
<style>
a{
  background-color:red
}
h1{
  background-color:blue
}
</style>
<body>

<h1><a>My First Heading</a></h1>

<p>My first paragraph.</p>

</body>
</html>

我很感激能得到的任何帮助。

最佳答案

尝试:

h1 a,h1{
    background-color:blue
}

DEMO.

关于html - 赋予 CSS 属性最高优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20394345/

相关文章:

javascript - 如何让js中创建的div在点击动态创建的td后填满屏幕?

javascript - 让一个选择的国家工作

css - Sass:如何在悬停时获得父选择器

javascript - 不能在html5中嵌套链接?

javascript - dragula - 如何禁用在其父容器中的拖动

html - css 图片不会显示

jquery - 为什么我的 jquery not 选择器不起作用

javascript - 如何设置整个按钮组的宽度?

javascript - 如何在当前滚动位置垂直居中对话框

html - 如何在选择选项的 HTML 标签中应用字体系列