css - 用媒体查询交换 3 个不同大小的 Logo ?

标签 css media-queries

我正在尝试根据不同的屏幕尺寸设置 3 种不同的 Logo 尺寸(smallmedbig)。这是我的代码:

@media screen and (max-width: 487px) {
  .site-header .site-branding {
    background-image: url("../images/logo_small.png") !important; 
  }
}

@media screen and (max-width: 1079px) {
  .site-header .site-branding {
    background-image: url("../images/logo_med.png") !important;
  }
}

@media screen and (min-width: 1080px) {
  .site-header .site-branding {
    background-image: url("../images/logo_big.png") !important;
  }
}

这可以从 big 切换到 med,但它不会再从 med 切换到 small .为什么?

最佳答案

也尝试在第二个媒体查询中使用最小宽度。即使屏幕很小,第二个查询也是正确的,最后一个 css 得到优先权,因此它加载第二个查询图像。 进行以下更改。

@media screen and (max-width: 487px) {
  .site-header .site-branding {
    background-image: url("../images/logo_small.png") !important; 
  }
}

@media screen and (min-width: 487px) and (max-width: 1079px) {
  .site-header .site-branding {
    background-image: url("../images/logo_med.png") !important;
  }
}

@media screen and (min-width: 1080px) {
  .site-header .site-branding {
    background-image: url("../images/logo_big.png") !important;
  }
}

关于css - 用媒体查询交换 3 个不同大小的 Logo ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21400065/

相关文章:

javascript - img 调整大小,但宽度将停止在 600

html - 修复 iPad 底部 iframe 内的 div

html - 在表格单元格的中心左对齐或右对齐文本

CSS 媒体查询互相覆盖

CSS 媒体查询,它不会将属性从 1024 更改为 768

css - 使用自定义 CSS 覆盖媒体查询中的样式

javascript - 模板化仅采用标题/内容参数的 HTML 代码块的简洁方法,其中内容可能很大且散布着换行符

javascript - Owlcarousel设置上传到服务器时不显示

高分辨率显示的 CSS @media 查询不起作用

html - CSS 媒体查询在断点处未按预期工作