我有以下CSS属性影响在我的网站上的网页上的内容显示。然而,我想排除该规则在移动设备上的应用。
请帮我修改一下。
--我正在自定义WordPress上应用它,附加CSS
.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%;
}发布于 2021-01-20 16:54:43
刚刚找到了一个完美的解决方案,将这些元素排除在移动设备上。您可以调整min-width上的像素条目,或者根据需要将其与max-width交换。
任意一条规则应用
@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%;
}
}和
@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%;
}发布于 2021-01-20 16:18:52
既然我们没有你的标记,我会即兴发挥:
// 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');
}
}
https://stackoverflow.com/questions/65813091
复制相似问题