【问题标题】:And selection with only 3 children (only CSS)并且选择只有 3 个孩子(只有 CSS)
【发布时间】:2023-01-17 23:01:43
【问题描述】:

如果所选元素恰好有 3 个子元素,我只想覆盖 CSS 属性

【问题讨论】:

标签: html css sass


【解决方案1】:

我认为使用纯 css 是不可能的,因为它不支持逻辑

一些替代方案:

使用 JS 的逻辑

function isElementHave3Child(elementId) {
  const el = document.getElementById(elementId);
  return element.childNodes.length === 3;
}

// and you can simply check the element and if the result are true append the override css class

element.classList.add("override-css-classname");

【讨论】:

    猜你喜欢
    • 2012-12-07
    • 2011-09-12
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多