简体   繁体   English

CSS媒体查询无法正确显示屏幕尺寸

[英]CSS media queries not displaying screen sizes correctly

I am currently trying to design a layout which will work for multiple screen sizes. 我目前正在尝试设计一种适用于多种屏幕尺寸的布局。 The screen sizes are listed below: 屏幕尺寸如下所示:

640x960 768x1280 1024x768 1366x768 1280x800 1366x768 1280x1024 640x960 768x1280 1024x768 1366x768 1280x800 1366x768 1280x1024

Based on the screen sizes, I want the box content height to fit within the screen size, so that there is no vertical scrollbar for a smaller window or any window sizes. 根据屏幕大小,我希望框内容的高度适合屏幕大小,以便没有用于较小窗口或任何窗口大小的垂直滚动条。

I tried the following, but it doesn't seem to be working correctly for the box, the height doesnt seem to adjust correctly based on the media queires, which is causeing the vertical scrollbar to show up; 我尝试了以下操作,但是对于盒子来说似乎无法正常工作,根据媒体查询,高度似乎无法正确调整,这导致垂直滚动条显示出来。 can someone show how this can be fixed? 有人可以显示如何解决此问题吗?

@media only screen and (min-width:640px) and (max-height:960px){
    .grid {
        height: 402px;     
        background:#ff3333;
    }
}
@media only screen and (min-width:768px) and (max-height:1280px) {
    .grid {
        height: 612px;     
        background:#33ff33;
        border:11px solid #33ff33 !important;
    }
}
@media only screen and (min-width:1024px) and (max-height:768px){
    .grid {
        height: 302px;     
        background: #55aaff;
        border:11px solid #55aaff !important;
    }
}
@media only screen and (min-width:1366px) and (max-height:768px){
    .grid {
        height: 329px;     
        background:#cccccc;
        border:11px solid #000000 !important;
    }
}
@media only screen and (min-width:1280px) and (max-height:800px){
        .grid {
            height: 539px;     
            background:#cccccc;
            border:11px solid pink !important;
        }
}    

 @media only screen and (min-width:1280px) and (max-height:1024){
                .gridStyle {
                    height: 539px;     
                    background:#cccccc;
                    border:11px solid yellow !important;
                }
 }

Any reason for not wanting a vertical scrollbar? 是否有不需要垂直滚动条的原因? You can just write a width based media query: 您可以编写基于宽度的媒体查询:

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

}

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

}

etc, and then use overflow-y: hidden; 等等,然后使用overflow-y: hidden;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM