【问题标题】:How can I remove my image css [duplicate]如何删除我的图像 css [重复]
【发布时间】:2016-05-29 12:45:02
【问题描述】:

我有以下代码:

.imgleft{
    background-image: url("logo.png");
    background-size: 100%;
    float: left;
}

...但我想让我的网站具有响应性,所以当我的宽度小于 650 时,我希望我的图片消失。

我尝试了以下代码,但它不起作用:

@media screen and (max-width: 650px) {
    .imgleft{
        background-color: none;
    }
}

【问题讨论】:

  • background-color: none; 无效。如果您希望它消失,请改用display: none;
  • background-image: none 为什么更改background-color 会对图像产生任何影响?

标签: html css


【解决方案1】:

您只是删除了图像的background-color,它不会隐藏它:)

试试display:none

@media screen and (max-width: 650px) {
    .imgleft{
        display: none;
    }
}

【讨论】:

    【解决方案2】:

    您将background-color 的值设置为none,而您应该将background-image 的值设置为none。

    那么,你想要达到的目标是:

    @media screen and (max-width: 650px) {
        .imgleft {
            background-image: none;
        }
    }
    

    (请参阅this Fiddle 进行演示)

    如果您不想要任何背景颜色或任何背景图像,您也可以这样做:

    @media screen and (max-width: 650px) {
        .imgleft {
            background-color: transparent;
            background-image: none;
        }
    }
    

    (请参阅this Fiddle 以获取演示)

    ...或者这个:

    @media screen and (max-width: 650px) {
        .imgleft {
            background: transparent;
        }
    }
    

    (另见this Fiddle

    【讨论】:

      猜你喜欢
      • 2011-11-30
      • 1970-01-01
      • 2010-11-30
      • 2020-08-11
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      相关资源
      最近更新 更多