CSS - media query样式不生效,被划掉

问题:

@media only screen and (max-width: 1200px) {
  .car-list {
    width: 300px;
    background-color: white;
  }
}
.car-list {
  width: 350px;
  height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  background-color: #01183f;
  position: absolute;
  margin: 10px 0;
  left: 10px;
  padding: 10px 20px;
  box-sizing: border-box;
  transition: all 0.3s;
  box-shadow: 0px 0px 10px 1px #2977a4 inset;
}

CSS - media query样式不生效,被划掉_第1张图片

样式被划掉,没有生效;

解决:

  • 给media query添加“!important”,提升优先级。

@media only screen and (max-width: 1200px) {
  .car-list {
    width: 300px !important;
    background-color: white !important;
  }
}
  • 在media query的样式前添加父级的类名(或id),也可以使其占据主导地位

@media only screen and (max-width: 1200px) {
  .map-dialog {
    .car-list {
      width: 300px;
      background-color: white;
    }
  }
}

 

你可能感兴趣的:(#,CSS,css,media,不生效)