【发布时间】:2021-09-03 03:52:36
【问题描述】:
我在HTML 中有一个div,它是从服务器端动态创建的。我想在HTML(front-end) 中应用css 仅在div 当且仅当它具有一些内容。如果它没有任何内容,那么我不需要应用新样式。
HTML代码示例为:
<div class="attr-marker">
Some-text-content <!-- Apply New Styling on it -->
</div>
<div class="attr-marker">
<!-- No need of new styling -->
</div>
<div class="attr-marker">
<!-- No need of new styling -->
<i class="fas fa-car" style="color:#d42424;font-size:px"></i>
</div>
而我尝试但失败的CSS是:
.attr-marker text {
display: block;
width: 12px;
height: 12px;
border-radius: 50%;
line-height: 12px;
font-size: 9px;
text-align: center;
background: #000;
color: #fff;
}
我可以通过使用javascript 来实现它,但我想要纯粹的CSS 解决方案,所以它可以帮助我最小化代码。
【问题讨论】:
-
css 样式选择器中的文本是什么?
-
它可以是
div中的任何文本,其中包含class: attr-marker。 -
我认为它不存在。 w3 文档中不存在标签名称“text”。
-
是的,我知道。这只是一个样本。
-
好的。明白了。
标签: javascript html css