【发布时间】:2016-09-04 11:28:54
【问题描述】:
我正在尝试使用 CSS/SCSS 制作自定义通知徽章。我想像在 HTML 代码中一样从 html 属性(data-badge)插入内容,但是当我在 CSS 上调用它时,它什么也没显示。
HTML
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li>
<a href="#" class="nav-icons"><i class="material-icons" data-badge="4">info</i></a>
</li>
<li>
<a href="#" class="nav-icons"><i class="material-icons">email</i></a>
</li>
<li>
<a href="#" class="dropdown-button" data-activates="dropdown-user">
<div class="chip">
<img src="/images/personal.png" alt="Contact Person">
Jane Doe
<i class="material-icons right">arrow_drop_down</i>
</div>
</a>
</li>
</ul>
SCSS
a.nav-icons {
max-height: 60px !important;
i.material-icons {
max-height: 60px;
font-size: 2rem;
line-height: 60px;
&[data-badge] {
content: attr(data-badge);
position: relative;
color: #fff;
&::after {
content: attr(data-badge);
position: absolute;
background: red;
border-radius: 50%;
display: block;
padding: 0.3em;
color: black;
font-size: 12px;
max-height: 20px;
max-width: auto;
right: -10px;
top: 8px;
}
}
}
}
或者,请看下面这个小提琴。
https://jsfiddle.net/5gxudefb/3/
提前谢谢你
【问题讨论】:
-
你的菜单打不开,没有javascript代码?
-
@MortezaQorbanAlizade 哪个菜单?我忘了在移动课上删除隐藏,但我编辑了小提琴。实际上与 javascript/侧边栏菜单/下拉菜单无关。我只需要知道为什么是这个内容:attr(data-badge);不适用于 SCSS