gpt4 book ai didi

css - 媒体查询不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 10:10:27 27 4
gpt4 key购买 nike

我完全是响应式设计的新手。我的媒体查询不起作用。当我调整窗口大小时,它不会重新调整我猜的断点。我制作了两个 div,其中一个用于桌面 View ,另一个用于平板电脑 View 。我使用 display: none 属性来获得桌面和移动版本。

另一个问题是,有没有办法为所有移动设备配置媒体查询?或者我应该为每个方便的 inviduel 组编写 css 吗? (例如 iphone5、iphone6、nexus 等。)

.tablet-view{
display: none;
}

.desktop-view{
display: inline;
}
/* ----------- iPad mini ----------- */

/* Portrait and Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 1) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* Portrait */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* ----------- iPad 1 and 2 ----------- */
/* Portrait and Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 1) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* Portrait */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* ----------- iPad 3 and 4 ----------- */
/* Portrait and Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (-webkit-min-device-pixel-ratio: 2) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* Portrait */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}
}

/* Landscape */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2) {
.desktop-view{
display:none;
}.tablet-view {

display: inline;
}

}

最佳答案

您正在使用 device-width。当您调整浏览器窗口大小时,您不会更改设备的宽度,因此媒体查询不适用。在不同的设备上或使用 DevTools 中的 Chrome 设备模式尝试。

关于css - 媒体查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37653125/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com