【问题标题】:media queries : limit some css styles according to the screen size媒体查询:根据屏幕大小限制一些 CSS 样式
【发布时间】:2026-01-28 16:00:02
【问题描述】:

当我在 layout.css 中编写一些样式时,它适用于每个屏幕尺寸和 /* #Media Queries 部分,你有这些部分:

/* Smaller than standard 960 (devices and browsers) */
/* Tablet Portrait size to standard 960 (devices and browsers) */
/* All Mobile Sizes (devices and browser) */
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */

所以这些都不是我想要的。

我应该在哪里编写大屏幕特定的 css 代码?

【问题讨论】:

  • /************************************************ ******************************************* 小于 1280 **** ****************************************************** *******************************/ @media screen and (max-width: 1280px) { 你的css在这里选择什么你想要的视口}

标签: html css media-queries


【解决方案1】:

假设你有一个像<div claas="example"> </div>这样的div

现在为.example 编写一个css,它将应用于那些大于您在媒体查询中提到的范围的屏幕

.example{
  /*..for larger screen style goes here....*/
 }
@media screen and (max-width: 1400px) { 
  .example {
    /*...now give style for those screen which are less than 1400px...*/
  }
}
@media screen and (max-width: 1300px) {
  .example {
    /*...now give style for those screen which are less than 1300px...*/
  }
}

在上面的代码中,您提到了

的三种不同样式
  1. >1400px 屏幕尺寸
  2. 适用于 1300 到 1400 像素的屏幕尺寸

编辑::

"/* 大于标准 960(设备和浏览器)*/"

.example{
  /*..style for larger than 960px....*/
 }
@media screen and (max-width: 960px) { 
  .example {
    /*..style for lesser than or equal to 960 px...*/
  }
}

【讨论】:

  • /* 大于标准 960(设备和浏览器)*/ @media only screen and (min-width: 960px) { }