html - 仅当父元素在 Sass 中没有特定类时才绘制边框
问题描述
我想改变我的 SASS 代码的行为。当前的 SASS 代码总是绘制border
onfocus
事件。border
它应该只在其父元素select2-container
没有类时绘制select2-container--disabled
。我怎样才能做到这一点?
HTML
<select name="product" id="nbp__name-dropdown" class="form-control select2-hidden-accessible" disabled="" data-select2-id="nbp__name-dropdown" tabindex="-1" aria-hidden="true"></select>
<span class="select2 select2-container select2-container--default select2-container--disabled select2-container--focus" dir="ltr" data-select2-id="2" style="width: 377.5px;">
<span class="selection">
<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="-1" aria-labelledby="select2-nbp__name-dropdown-container">
<span class="select2-selection__rendered" id="select2-nbp__name-dropdown-container" role="textbox" aria-readonly="true">
<span class="select2-selection__placeholder">Select a product...</span>
</span>
<span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
</span>
</span>
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
SASS
.select2-selection--single {
&:focus {
border: 1px solid $focus-border-color;
}
}
解决方案
只有当它的父元素 select2-container 没有 select2-container--disabled 类时,它才应该绘制边框。我怎样才能做到这一点?
我无法让你的代码在 CodePen 中工作,所以我做了一个例子,因为我也很好奇你是否可以使用 :not 与父母一起使用。如果我理解你,如果要加边框的元素的父级没有禁用类,你不想画边框。直接用 CSS 做的,不涉及 SASS :)
所以这个例子有效 - 中间段落不会有边框:
HTML
<html>
<head>
</head>
<body>
<div class="chalk">
<p class="one">This one should be bordered</p>
</div>
<div class="chalk disabled">
<p class="one">This one should not be bordered</p>
</div>
<div class="chalk">
<p class="one">This one should be bordered</p>
</div>
</body>
CSS
div:not(.disabled) .one {
border: 1px solid black;
}
推荐阅读
- ios - Swift 子类复杂子类型
- c# - 在 FHIR 服务器中使用 Fire.Ly 开源库
- node.js - Express:POST 不发送数据 - 未定义 var
- python - 如何以可跨 Linux、Windows 和 MacOS 移植的方式收集 Python 3 中的当前架构?
- python - PVLIB 可以用于热点建模吗?
- payment-processing - PCI 合规性 - 托管在 AWS 上的应用程序不存储卡数据
- sql - sql查询获取每个id的最新记录
- c++ - C++ - 与非平凡类成员类型的联合?
- java - 示例 javaclient 正在工作,来自 JAVA-APPLICATION 表示无法找到请求目标的有效认证路径
- jquery - 如何有这样的滚动动画和图像?