简体   繁体   English

如何在媒体查询中隐藏图像?

[英]How can i hide image in media queries?

i want to hide my large size social media icon on media queries specially for small-medium devices. 我想在专门针对中小型设备的媒体查询上隐藏我的大型社交媒体图标。 I want to replace the large size of the icon to small size which fits inside the device container size. 我想将图标的大尺寸替换为适合设备容器尺寸的小尺寸。 I have tried width-100% but it is not working, giving that value will make my icon more large. 我尝试了width-100%,但它不起作用,给该值会使我的图标变大。 Here is my html and css code for the 360. 这是我的360的HTML和CSS代码。

@media only screen and (max-width:360px) {} @media only屏幕和(最大宽度:360px){}

<div class="social1">

                <a href="#"><img src="http://i.imgur.com/eIGaLt0.png" alt="Facebook" class="fb">
                   </a>

            </div>    

CSS 的CSS

 .fb {
            width:100%;
            height:auto;

    }

When you add a width of 100%, the element will use the full width of its parent element, which in this case is greater than the actual image width. 当您添加100%的宽度时,该元素将使用其父元素的完整宽度,在这种情况下,该宽度大于实际的图像宽度。 So that is why the image becomes large when you reduce the screen size. 因此,减小屏幕尺寸时图像变大。

So, in this case if you want the size of the image to be reduced only for a device width of 360 or less, provide a fixed width. 因此,在这种情况下,如果只想减小设备宽度为360或更小的图像尺寸,请提供固定的宽度。

.fb {       
   width:15px; // or whatever width seems right for your case
   height:auto;
}

You can also provide width in percentage, but you should keep in mind the width of the parent element for this. 您也可以按百分比提供宽度,但是应牢记为此的父元素的宽度。

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

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