【问题标题】:two screen widths: 375px and 1024px两种屏幕宽度:375px 和 1024px
【发布时间】:2019-06-04 12:14:25
【问题描述】:

如何以两种屏幕宽度(375 像素和 1024 像素)构建网站?网站不需要响应两者之间的宽度。

@media only screen and (min-width : 375px) and (max-width : 1024px) 据我所知,这个标签媒体工作在 375 和 1024 之间。也许使用断点是正确的方法。有什么建议吗?

【问题讨论】:

  • 你想max-width: 375px 并为下面的任何东西构建,那将是你的screen1 然后min-width: 1024 那将是screen2
  • 是的,您可以对特定设备使用媒体查询。对于特定屏幕,您可以添加断点,如 362px 到 456px 等。

标签: css css-selectors media-queries


【解决方案1】:

最好设计你的 CSS mobile-first,这意味着你的 CSS 文件看起来有点像这样:

CSS:
// Basic CSS
div {
  height: 200px;
  width: 200px;
  background-color: yellow;
}

@media screen and (min-width: 375px) {
  div {
    height: 150px;
  } 
}

@media screen and (min-width: 1024px) {
  div {
    height: 100px;
    background-color: red;
  }

这样你就有了一个在断点上以三种不同方式呈现的 div

  1. 0 - 374 像素,200x200 像素的正方形,黄色背景
  2. 375px - 1023px 这是一个黄色背景的 150x200 像素的矩形
  3. 1024 像素及以上是一个 100x200 像素的矩形,背景为红色

这样你就不会重复太多,你的代码保持干净,你只覆盖必要的。

【讨论】:

    【解决方案2】:

    我也为所有具有纵向模式的设备提供媒体查询。我也使用断点获得了媒体查询 CSS。使用此媒体查询以获得更好的用途,并且此答案中包含的肖像设备:

    /* 
      ##Device = Desktops
      ##Screen = 1281px to higher resolution desktops
    */
    
    @media (min-width: 1281px) {
    
      //CSS
    
    }
    
    /* 
      ##Device = Laptops, Desktops
      ##Screen = B/w 1025px to 1280px
    */
    
    @media (min-width: 1025px) and (max-width: 1280px) {
    
      //CSS
    
    }
    
    /* 
      ##Device = Tablets, Ipads (portrait)
      ##Screen = B/w 768px to 1024px
    */
    
    @media (min-width: 768px) and (max-width: 1024px) {
    
      //CSS
    
    }
    
    /* 
      ##Device = Tablets, Ipads (landscape)
      ##Screen = B/w 768px to 1024px
    */
    
    @media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    
      //CSS
    
    }
    
    /* 
      ##Device = Low Resolution Tablets, Mobiles (Landscape)
      ##Screen = B/w 481px to 767px
    */
    
    @media (min-width: 481px) and (max-width: 767px) {
    
      //CSS
    
    }
    
    /* 
      ##Device = Most of the Smartphones Mobiles (Portrait)
      ##Screen = B/w 320px to 479px
    */
    
    @media (min-width: 320px) and (max-width: 480px) {
    
      //CSS
    
    }
    

    【讨论】:

      猜你喜欢
      • 2022-12-23
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2018-05-30
      • 1970-01-01
      • 2014-12-21
      相关资源
      最近更新 更多