加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 如果div不存在,你可以在CSS中应用CSS规则吗?

发布时间:2020-12-14 19:32:18 所属栏目:资源 来源:网络整理
导读:这是可能的,用CSS? 如果.div1不存在,则应用此规则: .div2{ property: value; } 喜欢 div class="div1".../divdiv class="div2" !-- it exists,so do nothing --/div 和 div class="div2" !-- it doesn't exist,apply the css --/div 解决方法 如果你知道di
这是可能的,用CSS?

如果.div1不存在,则应用此规则:

.div2{
  property: value;  
}

喜欢

<div class="div1">
...
</div>

<div class="div2">
 <!-- it exists,so do nothing -->
</div>

<div class="div2">
 <!-- it doesn't exist,apply the css -->
</div>

解决方法

如果你知道div的’unsyled’样式,你可以使用一个css兄弟选择器来设计它的方式,如果它遵循.div1,而’plain’的方式,如果它不 –
.div2 {
    /* styled however you want */
}
.div1 + .div2 {
    /* 'plain' styling */
}

See the fiddle.尝试删除div1看到div2,因为它将被风格没有div1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读