为什么启用触摸模式时媒体查询会被忽略?

发布于 2025-01-18 14:24:17 字数 2156 浏览 4 评论 0原文

当我使用 vanilla JS 创建简单的网站时,我曾经使用过媒体查询,但今天我使用 React JS 来完成它,如果有问题的话,IDK。每当网站在屏幕上响应时(例如移动设备或任何带有触摸内容的屏幕)媒体查询很容易被忽略,就像我从未写过它们一样。例如:如果我关闭触摸模拟,一切都很好。

我尝试将媒体全部更改为媒体屏幕之类的东西,但没有一个起作用。

// media queries width & height

@media (max-width: 810px) and (max-height: 1080px) {
    .platform {
        // width: 70%;
        height: 60%;
    }
}

@media (max-width: 768px) and (max-height: 1024px) {
    .platform {
        width: 80%;
        height: 70%;
    }
}

// media queries height

@media (max-height: 600px) {
    .platform {
        width: 100%;
        height: 100%;
    }
}
// media queries width

@media (max-width: 625px) {
    .platform {
        width: 100%;
        height: 100%;
    }
}

@media (max-width: 501px) {
    .title {
        font-size: 3rem;
    }

    .instructions {
        width: 25rem;
        font-size: 1.4rem;
    }

    .die-container {
        gap: 10px;
        width: 25rem;
    }

    .die-item {
        width: 72px;
        height: 72px;
    }
}

@media (max-width: 430px) {
    .title {
        font-size: 2.8rem;
    }

    .instructions {
        width: 23rem;
        font-size: 1.3rem;
    }

    .die-container {
        gap: 10px;
        width: 22rem;
    }
    .die-item {
        width: 62px;
        height: 62px;
    }
}

@media (max-width: 390px) {
    .title {
        font-size: 2.5rem;
    }

    .instructions {
        width: 20rem;
        font-size: 1.2rem;
    }

    .die-container {
        gap: 10px;
        width: 20rem;
    }
    .die-item {
        width: 56px;
        height: 56px;
    }
}

@media (max-width: 340px) {
    .instructions {
        width: 19rem;
        font-size: 1.1rem;
    }

    .die-container {
        gap: 10px;
        width: 19rem;
    }
    .die-item {
        width: 50px;
        height: 50px;
    }
    .roll-dice {
        width: 8rem;
    }
}

@media (max-width: 340px) {
    .instructions {
        width: 18rem;
        font-size: 1rem;
    }

    .die-container {
        gap: 10px;
        width: 18rem;
    }
    .die-item {
        width: 50px;
        height: 50px;
    }
    .roll-dice {
        width: 8rem;
    }
}

I have worked with media queries when I was creating simple sites with vanilla JS, but today I did it using React JS, IDK if it is problem or not.. Whenever site is responding on screen like mobile or any screen with touch stuff media queries are simple ignored like I have never wrote them.. for ex: If I will turn off touch simulation everything is fine.

I have tried to change media all to media screen and stuff like this but none of them have worked..

// media queries width & height

@media (max-width: 810px) and (max-height: 1080px) {
    .platform {
        // width: 70%;
        height: 60%;
    }
}

@media (max-width: 768px) and (max-height: 1024px) {
    .platform {
        width: 80%;
        height: 70%;
    }
}

// media queries height

@media (max-height: 600px) {
    .platform {
        width: 100%;
        height: 100%;
    }
}
// media queries width

@media (max-width: 625px) {
    .platform {
        width: 100%;
        height: 100%;
    }
}

@media (max-width: 501px) {
    .title {
        font-size: 3rem;
    }

    .instructions {
        width: 25rem;
        font-size: 1.4rem;
    }

    .die-container {
        gap: 10px;
        width: 25rem;
    }

    .die-item {
        width: 72px;
        height: 72px;
    }
}

@media (max-width: 430px) {
    .title {
        font-size: 2.8rem;
    }

    .instructions {
        width: 23rem;
        font-size: 1.3rem;
    }

    .die-container {
        gap: 10px;
        width: 22rem;
    }
    .die-item {
        width: 62px;
        height: 62px;
    }
}

@media (max-width: 390px) {
    .title {
        font-size: 2.5rem;
    }

    .instructions {
        width: 20rem;
        font-size: 1.2rem;
    }

    .die-container {
        gap: 10px;
        width: 20rem;
    }
    .die-item {
        width: 56px;
        height: 56px;
    }
}

@media (max-width: 340px) {
    .instructions {
        width: 19rem;
        font-size: 1.1rem;
    }

    .die-container {
        gap: 10px;
        width: 19rem;
    }
    .die-item {
        width: 50px;
        height: 50px;
    }
    .roll-dice {
        width: 8rem;
    }
}

@media (max-width: 340px) {
    .instructions {
        width: 18rem;
        font-size: 1rem;
    }

    .die-container {
        gap: 10px;
        width: 18rem;
    }
    .die-item {
        width: 50px;
        height: 50px;
    }
    .roll-dice {
        width: 8rem;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时浪漫 2025-01-25 14:24:17

您的媒体查询无法在移动设备上工作,因为您没有将视口宽度设置为设备宽度

尝试将以下内容添加到< head> index.html

<meta name="viewport" content="width=device-width, initial-scale=1" />

Your media queries don't work on mobile because you haven't set the viewport width to device width

Try adding the following to the <head> of your index.html

<meta name="viewport" content="width=device-width, initial-scale=1" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文