css - 如何使用来自其父级的 ::after 的通用兄弟选择器
问题描述
我想使用复选框中的状态来显示和隐藏一个 ::after,他是这个的一般兄弟。我正在使用此代码,也许您可以帮助我解决这个问题。谢谢。
.form-check label {
position: relative;
}
.form-check label:after {
content: " ";
height: 25px;
width: 25px;
display: block;
position: absolute;
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
right: -30px;
top: 0;
background-color: red;
}
.form-check [type="checkbox"]:checked~ ::after {
background-color: blue;
}
<div class="form-check">
<label class="form-check-label" for="example">
<input class="form-check-input" type="checkbox" value="" id="example">
<span>Example</span>
::after
</label>
</div>
解决方案
之后需要有一个元素<input>
才能使用这样的伪元素。在这种情况下,你有一个<span>
那里。
.form-check [type="checkbox"]:checked ~ span::after {
background-color: blue;
}
推荐阅读
- php - 如何在 laravel 5.5 中进行多次插入?
- javascript - 使用引导程序时,下拉菜单在移动屏幕上不起作用
- python - 在 Python 中注册要在事件上调用的函数
- python - 阅读 youtube HTML 时,requests.get() 没有返回正确的文本顺序
- tensorflow - 来自 CMake 的 BUILD 文件,用于自定义操作 tensorflow 服务
- google-cloud-platform - 如何 pip 安装谷歌云异常
- javascript - 查询和改变firebase实时数据库多对多(双向)关系
- python - 当使用来自_tensor_slices() 的Tensorflow 数据集时,是否可以在每个训练步骤都加载一个新批次?
- python - 如何使用新词汇增量训练 word2vec 模型
- ruby-on-rails - 正则表达式 - 除 1-9 或 a-zA-Z 之外的任何可打印字符