简体   繁体   English

仅屏幕和(最小宽度:0px)和(最大宽度:327px)不起作用

[英]only screen and (min-width: 0px) and (max-width: 327px) not work

responsive in html and div tag is not work. 响应在html和div标签中不起作用。

my head code is 我的邮政编码是

<link media="only screen and (min-width: 0px) and (max-width: 327px)" rel="stylesheet" type="text/css" href="mobile.css">

and my body code is 我的身体密码是

<div id="div1">

    <div class="he" style="background-color: #65a82a; height: 40px: 10px " >
        <span class="ac" style="margin: 10px 7px 5px 3px;color: white;font-size: 3vmax;">   لینک مستقیم اشتراک گذاری در وبسایت و شبکه های اجتماعی :</span>
    </div>
    <div class="ad" style="text-align: left;margin: 18px">
        <a href="<?php echo $imgsrc[0]; ?>"> <span style="color: black;font-size: 17px"> https://pic.leanilo.com/wp-content/uploads/2019/03/1553530968n8g4k.jpg </span></a></div></div>

and tablet.css code is 和tablet.css代码是

.he{background-color: red; height: 55px;margin: 10px}

Specificity of CSS rules at play here. CSS规则的特殊性在这里发挥作用。 You can see in your inspector the rule you wanted is crossed out and the other rule is instead applied. 您可以在检查器中看到您想要的规则被划掉,而另一个规则被应用。 This is because inline styles outweigh ordinarily declared class selectors. 这是因为内联样式胜过通常声明的类选择器。 To fix move the inline style off of the style attribute on the image, and move those styles to your stylesheet. 要修复,将内联样式从图像的style属性中移出,然后将这些样式移到样式表中。 Then your media query should override at the correct width. 然后,您的媒体查询应以正确的宽度覆盖。

For example, in this snippet you can see that the div with class .he has a background color of red in the CSS rule, but when you run the snippet the background is green because you have a style attribute on that element with the green background color ( style="background-color: #65a82a; height: 2.8vmax;margin: 10px " ). 例如,在此代码段中,您可以看到类class .he的div在CSS规则中具有red的背景色,但是在运行该代码段时,背景为绿色,因为在该元素上具有绿色背景的style属性color( style="background-color: #65a82a; height: 2.8vmax;margin: 10px " )。

 .he { background-color: red; height: 55px; margin: 10px; } 
 <div class="he" style="background-color: #65a82a; height: 2.8vmax;margin: 10px " > <span class="ac" style="margin: 10px 7px 5px 3px;color: white;font-size: 3vmax;"> لینک مستقیم اشتراک گذاری در وبسایت و شبکه های اجتماعی :</span> </div> 

This is called inline styles and the inline styles win in the case where they are targeting rules that are also declared in the CSS. 这称为内联样式,当内联样式的目标是也在CSS中声明的规则时,内联样式会获胜。 The media queries will work the same way. 媒体查询将以相同的方式工作。

To fix the problem move the styles out of the HTML and into CSS, then you will have a more expected result: 要解决此问题,请将样式从HTML移到CSS,然后将得到更理想的结果:

 .he { background-color: #65a82a; height: 40px: } .ac { margin: 10px 7px 5px 3px; color: white; font-size: 3vmax; } @media only screen and (max-width: 327px) { .he { background-color: red; /* these styles now applied */ height: 55px; margin: 10px; } } 
 <div class="he"> <span class="ac"> لینک مستقیم اشتراک گذاری در وبسایت و شبکه های اجتماعی :</span> </div> 

Run the snippet and change your screen size to see the media query working. 运行该代码段并更改屏幕尺寸,以查看媒体查询的运行情况。

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

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