简体   繁体   English

为div覆盖CSS类的某些属性

[英]overding some properties of css class for a div

我有一个div,我向其应用css类。现在在css类中,heigh被标为x px,但我希望我的div为y px。如何在不更改CSS的情况下覆盖CSS的高参数。

<div style="height: 80px"></div>

The browser assigns the styles with the highest specificity to the elements. 浏览器为元素分配具有最高特异性的样式。 As you can read here 'style' has the highest specificity. 如您所读, “风格”具有最高的特异性。

You can override specificity by using the !important declaration . 您可以使用!important声明覆盖特定

There are several ways to override the value of a CSS attribute defined in a class. 有几种方法可以覆盖类中定义的CSS属性的值。

This is really a huge topic, though -- so if you really want to understand this stuff, start here with a tutorial on CSS Specificity. 但是,这确实是一个巨大的话题-因此,如果您真的想了解这些内容,请 CSS特异性教程开始

使用内联css与!important标签

<div class="yourclass" style="height:ypx!important">

您需要更改CSS才能覆盖它-使用级联为其赋予新值,或添加优先于外部样式声明的内联style属性(请注意!important )。

CSS declarations cascade . CSS声明级联 Meaning you can attach additional rules to other CSS classes and assign both to an element: 这意味着您可以将其他规则附加到其他CSS类,并将两者都分配给一个元素:

<style type="text/css">
.style1 {
  color: red;
  height: 100px;
}
.style1.style2 {
  height: 200px;
}
</style>

<!-- This DIV will have a height of 200px and red foreground color -->
<div class="style1 style2"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM