首页 > 解决方案 > 如何让以下媒体查询适用于 480 像素?

问题描述

我正在尝试css对媒体查询最大宽度执行以下操作,480px但出于某种奇怪的原因,没有任何效果。我的其他媒体查询很好,但对于这个特定的查询,没有任何改变。我认为 em480px30em? 我已经包含了我的代码的一部分:

@media screen and (max-width: 480px) and (orientation: portrait) {
label {
  width: 100%;
  display: block;
  position: relative;

}

.nav {
  width: 200%;

}

#nav-icon {
  font-size: 28px;
  line-height: 50px;
  padding-left: 1em;
  color:  #ffffff;
  background-color: #f44336;
}

div.nav ul, div.nav li, label{
  line-height: 50px;
  margin: 0;
  padding: 0 2em;
  list-style: none;
  text-decoration: none;
  color: #000;
  font-weight: 100;
  width: 150%;
  position: relative;
  font-size: .9em;
  }

div.header2_welcome h1{
  text-align: center;
  font-family: 'Pacifico', cursive;
  font-size: 1.5em;
  position: absolute;
  top: 5em;
  right: 0em;
  text-decoration: none;
  white-space: nowrap;
}

在此处输入图像描述

@media only screen and (max-width : 1200px) {

}

@media only screen and (max-width : 979px) {

}

@media only screen and (max-width : 767px) {

}

@media only screen and (max-width : 480px) {

}

@media only screen and (max-width : 320px) {

}

标签: htmlcssstylesmedia-queries

解决方案


对现有媒体查询使用 min-width

@media screen and (min-width: 320px and max-width: 480px) and (orientation: portrait) {

}

还要检查是否有任何 CSS 库覆盖了您的样式。如果是这样,请尝试在所有其他 css 文件之后加载此自定义 css


推荐阅读