简体   繁体   English

如何确定媒体查询和CSS之间的优先级?

[英]How can I decide the priority between media queries and css?

I have a page.css used from the master page to others pages. 我有一个从母版页到其他页的page.css。 In that file I have a property for a div: <div class="classDivOne">Hello</div> that is: 在该文件中,我有一个div属性: <div class="classDivOne">Hello</div>即:

.classDivOne{
margin-top:5px;
}

Now, with windows explorer everything is fine. 现在,使用Windows资源管理器,一切都很好。

Instead with Chrome I need to fix margin-top:0px; 相反,我需要使用Chrome修复margin-top:0px; .

I used media queries (inside master page) in this way: 我以这种方式使用媒体查询(在母版页内部):

<style type="text/css">
   @media screen and (-webkit-min-device-pixel-ratio:0) {
        .classDivOne{
            margin-top:0px;
        }
   }
</style>

but I noted that the file css is the primary choice and my media screen for chrome is not used. 但我注意到文件css是首要选择,并且未使用我的Chrome媒体屏幕。 If I put into the div style="margin-top:0px" I have the same result. 如果我放入div style="margin-top:0px"我将得到相同的结果。

How can I set the priority into the choice of css for that div? 如何在该div的CSS选择中设置优先级? Or there is a different solution? 还是有其他解决方案?

write this way 这样写

<style type="text/css">
   @media screen and (-webkit-min-device-pixel-ratio:0) {
        .classDivOne.classDivOne{
            margin-top:0px;
        }
   }
</style>

or 要么

<style type="text/css">
   @media screen and (-webkit-min-device-pixel-ratio:0) {
        .classDivOne{
            margin-top:0px !important;
        }
   }
</style>

CSS : CSS:

<style type="text/css">
   @media screen and (-webkit-min-device-pixel-ratio:0) {
        .classDivOne{
            margin-top:0px !important;
        }
   }
</style>


! important 

is used to make the priority of property higher than other. 用于使属性的优先级高于其他属性。

<style type="text/css">
@media
only screen and (-webkit-min-device-pixel-ratio: 0),
only screen and (   min--moz-device-pixel-ratio: 0),
only screen and (     -o-min-device-pixel-ratio: 0),
only screen and (        min-device-pixel-ratio: 0),
only screen and (                min-resolution: 0dpi),
only screen and (                min-resolution: 0px) { 

  .classDivOne{
            margin-top:0px !important;
        }

}

/*OR*/

@media screen and/*!*/(-webkit-min-device-pixel-ratio:0) { 
        .classDivOne{
            margin-top:0px !important;
        }

 }
</style>

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

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