gpt4 book ai didi

javascript - 如何在一行中为移动设备和桌面设备分配一个 css 值

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:00 26 4
gpt4 key购买 nike

我有宽度为 190 像素的 HTML div,它在桌面上正常工作,但在移动设备上却不行,有没有办法判断连接是否来自桌面采用此值,否则采用此值?

这是我的代码:

document.querySelector('.article').style.width ='190px';

最佳答案

在你的 css 文件中

// Desktop
.article {
width: 100px;
}


// Mobile
@media only screen and (max-width: 768px) {
.article {
width: 50px;
}
}

这是 Media Queries .

在第一行中,我们没有任何限制,但是当屏幕宽度小于时,您覆盖当前值ONLY 768px

关于javascript - 如何在一行中为移动设备和桌面设备分配一个 css 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54253764/

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