html - 更高分辨率的媒体查询

标签 html css media-queries resolution

我坚持这个决议。 我正在为以下分辨率编写 CSS。

a.      800x600
b.      1024x768
c.      1280x800 and 1280x1024
d.      1366x768
e.      1920x1080
f.      2560x1440

And my laptop resolution is 1366*768, I have done CSS queries till there, but the problem arising now is how I write CSS for 1920*1080 and 2560*1440

I am testing the resolutions by changing the inspect element of chrome.

I have tried to code for 1920*1080, but it is only working if I am removing the code of 1366*768, means at a time only one code is running.

Here is my code of CSS:

@media only screen and (max-device-width: 800px) and (max-device-height: 600px){
  .tab-menu
  {
      padding: 0px;
      width: 16.2%;
      margin-right: 1px !important;
  }
    .tab-menu a
    {
        font-size: 13px !important;
    }
    .main
    {
        width: 10%;
    }
    .other
    {
        width: 10%;
    }
    .sku
    {
        width: 10%;
    }
    .adjust-height
    {
        width: 100px;
    }
    .table
    {
        font-size: 13px;
    }
    .w-line
    {
        width : 9.2%;
    }
    .w-store
    {
        width: 9%;
    }
    .w-item{
        width: 13.3%;
    }
    .w-item-name{
        width:22.4%;
    }
    .w-qty
    {
        width: 10%;
    }
    .w-uom
    {
        width: 5%;
    }
    .w-price
    {
        width: 10%;
    }
    .w-total
    {
        width: 1.4%;
    }
    .w-blank
    {
        width: 2%;
    }



}





@media all and (-ms-high-contrast:none) and (max-device-width: 800px) and (max-device-height: 600px) {
    *::-ms-backdrop,.w-line {
        width: 9%;
    }
    *::-ms-backdrop,.w-qty {
        width: 9%;
    }
    *::-ms-backdrop,.w-price {
        width: 10%;
    }
}




@media only screen and (max-device-width: 1280px) and (max-device-height: 720px){
    .bottom-grid
    {
        height: 130px;
    }
    .adjust-height
    {
        width: 130px;
    }
    @-moz-document url-prefix() {
        .bottom-grid
        {
            height: 120px;
        }
    }
    *::-ms-backdrop,.bottom-grid {
        height: 121px;
    }
}


@media only screen and (max-device-width: 1280px) and (max-device-height: 768px){
    .adjust-height
    {
        width: 130px;
    }
}



@media only screen and (max-device-width: 1920px) and  (max-device-height: 1080px){
    body
    {
        overflow-x: hidden;
    }
    .adjust-height
    {
        width: 200px;
    }
    .bottom-grid
    {
        height: 490px;
    }
    .tab-menu
    {
        width: 13.9%;
    }
    .foot-close
    {
        padding-right: 170px;
    }
    .tab-menu-left
    {
        padding-left:70px;
        padding-right:65px;
    }
    .tab-menu-right
    {
        padding-left: 0px;
        padding-right: 170px;
    }
    @-moz-document url-prefix() {
        .bottom-grid
        {
            height: 480px;
        }
    }
    *::-ms-backdrop,.bottom-grid {
        height: 480px;
    }
}


@media only screen and (max-device-width: 1366px) and (max-device-height: 768px) {
    .adjust-height
    {
        width:137px;
        transition: all 0.5s;
    }
    .tab-menu
    {
        width: 13.8%;
        text-align: center;
        margin-right:5px;
    }
    .tab-menu-left
    {
        padding-left:5px;
    }
    .tab-menu-right
    {
        padding-right:67px;
    }
    .bottom-grid
    {
        height:179px;
        width:100%;
        background-color: white;
        overflow-y: scroll;
        margin-left: 0px;
        margin-right: 0px;
        padding-left: 0px;
        padding-right: 0px !important;
    }
    .w-img
    {
        width: 5%;
    }
    .w-line
    {
        width: 7.2%;
    }
    .w-store
    {
        width: 10.4%;
    }
    .w-item
    {
        width: 14.3%;
    }
    .w-item-name
    {
        width: 24.4%;
    }
    .w-qty
    {
        width: 10.2%;
    }
    .w-uom
    {
        width: 6%;
    }
    .w-price
    {
        width: 7.8%;
    }
    .w-total
    {
        width:7.6%;
    }

    @-moz-document url-prefix() {
        .bottom-grid {
            height:167px;
        }
        .w-qty
        {
            width: 10.9%;
        }
    }

    @media all and (-ms-high-contrast:none)
    {

        *::-ms-backdrop,
        .bottom-grid {
            height: 165px;
            margin-bottom: 0px;
        } /* IE11 */
        *::-ms-backdrop,.main-footer
        {
        }*::-ms-backdrop,.blue-band
         {
             font-size: 14px;
         }
        *::-ms-backdrop,.form-control
        {
            padding: 3px 6px;
        }
        *::-ms-backdrop,.select2-selection__arrow b
        {
            top:25% !important;
        }
    }
}

提前致谢...

最佳答案

当使用 2 个或更多媒体查询时,它们在 CSS 中的顺序很重要。

这是一个“先变大”的解决方案,其中 body 开始为灰色,并在屏幕变小时发生变化

Fiddle demo

body {
  background: gray;
}

@media only screen and (max-width: 1000px) {
  body {
    background: red;
  }
}
@media only screen and (max-width: 800px) {
  body {
    background: blue;
  }
}
@media only screen and (max-width: 600px) {
  body {
    background: green;
  }
}

这是一个“先小”的解决方案,其中 body 开始是灰色的,并在屏幕变大时改变

注意,这里查询的顺序是和上面的max-width规则相比切换的

Fiddle demo

body {
  background: gray;
}

@media only screen and (min-width: 600px) {
  body {
    background: green;
  }
}
@media only screen and (min-width: 800px) {
  body {
    background: blue;
  }
}
@media only screen and (min-width: 1000px) {
  body {
    background: red;
  }
}

关于html - 更高分辨率的媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38304511/

相关文章:

html - 在 div 中有一个链接 没有两个悬停状态

html - 在本地 joomla 服务器文件中定位 html 代码

html - 为什么这个 html 表格在桌面上有响应,但在移动设备上却没有?

html - 单击时应用媒体查询特定样式

android - CSS @media 查询未检测到 Droid 2

html - Chrome 中没有打印预览

javascript - 使用 CSS 或 JavaScript 计算分页数

javascript - 如何突出显示新添加的表格行?

jquery 验证 css 不适用于一个表单字段

google-chrome - 媒体查询在我手动调整浏览器大小时有效,但在我使用 Chrome 的 'Responsive' 中的 'Inspection' 功能时无效