为什么启用触摸模式时媒体查询会被忽略?
当我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的媒体查询无法在移动设备上工作,因为您没有将视口宽度设置为设备宽度
尝试将以下内容添加到
的
< head>
index.htmlYour 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 yourindex.html