首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将移动设备排除在下列CSS规则之外

问如何将移动设备排除在下列CSS规则之外
EN

Stack Overflow用户
提问于 2021-01-20 15:59:47
回答 2查看 356关注 0票数 0

我有以下CSS属性影响在我的网站上的网页上的内容显示。然而,我想排除该规则在移动设备上的应用。

请帮我修改一下。

--我正在自定义WordPress上应用它,附加CSS

代码语言:javascript
复制
.entry-content, .entry-summary {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    margin-left: auto;
    margin-right: auto;
        width: 66.67%;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-20 16:54:43

刚刚找到了一个完美的解决方案,将这些元素排除在移动设备上。您可以调整min-width上的像素条目,或者根据需要将其与max-width交换。

任意一条规则应用

代码语言:javascript
复制
@media (min-width: 900px) { 
    .entry-content, .entry-summary {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    margin-left: auto;
    margin-right: auto;
    width: 66.67%;
    }
}

和

代码语言:javascript
复制
@media (min-width: 900px) { 
    .entry-content, .entry-summary {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    margin-left: auto;
    margin-right: auto;
    width: 66.67%;
}
票数 2
EN

Stack Overflow用户

发布于 2021-01-20 16:18:52

既然我们没有你的标记,我会即兴发挥:

​

代码语言:javascript
复制
// Get all elements with classes which you want to exclude if device has touch screen
let touch_divs1 = document.getElementsByClassName('entry-content');
let touch_divs2 = document.getElementsByClassName('entry-summary');
let is_touch_device = false;
// Check if device is a touch device
if ("ontouchstart" in document.documentElement) {
    is_touch_device = true;
}
// Go through all elements which have those classes and remove them
if (is_touch_device) {
    for (let i = 0; i < touch_divs1.length; i++) {
        touch_divs1[i].classList.remove('entry-content');
    }
    for (let i = 0; i < touch_divs2.length; i++) {
        touch_divs2[i].classList.remove('entry-summary');
    }
}

​

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65813091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档