简体   繁体   English

在媒体屏幕CSS中使用后,类无法正常工作

[英]class not work after use in media screen CSS

I have below style in my style.css: 我的style.css中具有以下样式:

.adbox {
    background: #304254;
    padding: 5px;
    border-radius: 4px;
    width: 468px;
    height: 66px;
    position: relative;
    float: left;
    margin-left: 20px;
    margin-top: 60px;
}

Now I used it in media screen code for responsive, like below: 现在,我在媒体屏幕代码中使用它进行响应,如下所示:

@media only screen and (max-width : 992px) {
    /* -=>Meta */
    .meta {
        margin-bottom: 15px;
    }

    /* -=>Blog Block */
    .blog-block h2 {
        margin: 15px 0 10px 0;
    }
    .blog-block .summary {
        height: auto;
    }

    .adbox {
      background: #304254;
      padding: 5px;
      border-radius: 4px;
      width: 458px;
      height: 66px;
      position: relative;
      float: left;
      margin-left: 231px;
      margin-top: -111px;
    }

}

HTML: HTML:

<div class="adbox">
  <a href="google.com">
   <img class="img-responsive tablighatextra" src="0098.in/uyedfuygwecgeifg/wp-content/uploads/2016/11/…; alt="تبلیغات" />
  </a>
</div>

Now it not work and in inspect element all code is not usable: 现在它不起作用,并且在inspect元素中所有代码都不可用:

在此处输入图片说明

and HTML code is below: HTML代码如下:

<div class="adbox"><a href="http://google.com"><img class="img-responsive tablighatextra" src="http://0098.in/uyedfuygwecgeifg/wp-content/uploads/2016/11/814d302fbaf4ba308e6eba7a7e7b6f28.gif" alt="تبلیغات" /></a></div>

if you try removing the 'screen' or 'only' and using only the media? 如果您尝试删除“屏幕”或“仅”并仅使用媒体?

If it work, you are an step closer to the solution. 如果可行,则您离解决方案更近了一步。 It worked for me many times. 它为我工作了很多次。

check this fiddle 检查这个小提琴

it seems to be working fine. 它似乎工作正常。 Check your CSS, media queries should be at the bottom of your CSS. 检查您的CSS,媒体查询应位于CSS的底部。

.adbox {
    background: #304254;
    padding: 5px;
    border-radius: 4px;
    width: 468px;
    height: 66px;
    position: relative;
    float: left;
    margin-left: 20px;
    margin-top: 60px;
}

@media only screen and (max-width : 992px) {
    /* -=>Meta */
    .meta {
        margin-bottom: 15px;
    }

    /* -=>Blog Block */
    .blog-block h2 {
        margin: 15px 0 10px 0;
    }
    .blog-block .summary {
        height: auto;
    }

    .adbox {
      background: #304254;
      padding: 5px;
      border-radius: 4px;
      width: 458px;
      height: 66px;
      position: relative;
      float: left;
      margin-left: 231px;
      margin-top: -111px;
    }

}

As I found both the rules have common properties. 我发现这两个规则具有共同的属性。 So if two rules have exactly the same selector and both have common properties then the values of lastly declared rules will be applicable (if none of them have !important). 因此,如果两个规则具有完全相同的选择器并且都具有相同的属性,那么最后声明的规则的值将适用(如果它们都不具有!important)。 So I assume that your media query is declared before the rule that have the same properties. 因此,我假设您的媒体查询是在具有相同属性的规则之前声明的。

Solution : 解决方案:

@media only screen and (max-width : 992px) {
/* your other rules */

    .adbox {
    margin-left: 231px !important;
    margin-top: -111px !important;
    }
}

I removed other values as they have not changed inside media query. 我删除了其他值,因为它们在媒体查询中没有更改。

other solution is that you declare media query section after your rule that appears in media query (.adbox). 另一种解决方案是您在出现在媒体查询(.adbox)中的规则之后声明媒体查询部分。

尝试在每种样式的末尾添加!important ,例如padding: 5px !important;

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

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