html+css:按钮上显示消息数量精简代码

效果如图
这里写图片描述
这个很多人可能没思路,其实就是a标签里面加个显示数量的div

<a href="index.html" class="nav-link">aaa<div class="nav-counter nav-counter-blue">4</div></a>

但是复杂的是css代码,如下

.nav-link {
  position: relative;
  padding: 0 14px;
  line-height: 34px;
  font-size: 10px;
  font-weight: bold;
  color: #555;
  text-decoration: none;
}
.nav-link:hover {
  color: #333;
  text-decoration: underline;
}

.nav-counter {
  position: absolute;
  top: -1px;
  right: 1px;
  min-width: 8px;
  height: 20px;
  line-height: 20px;
  margin-top: -11px;
  padding: 0 6px;
  font-weight: normal;
  color: white;
  text-align: center;
  text-shadow: 0 1px rgba(0, 0, 0, 0.2);
  background: #e23442;
  border: 1px solid #911f28;
  border-radius: 11px;
  background-image: -webkit-linear-gradient(top, #e8616c, #dd202f);
  background-image: -moz-linear-gradient(top, #e8616c, #dd202f);
  background-image: -o-linear-gradient(top, #e8616c, #dd202f);
  background-image: linear-gradient(to bottom, #e8616c, #dd202f);
  -webkit-box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.1), 0 1px rgba(0, 0, 0, 0.12);
  box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 0.1), 0 1px rgba(0, 0, 0, 0.12);
}

.nav-counter-green {
  background: #75a940;
  border: 1px solid #42582b;
  background-image: -webkit-linear-gradient(top, #8ec15b, #689739);
  background-image: -moz-linear-gradient(top, #8ec15b, #689739);
  background-image: -o-linear-gradient(top, #8ec15b, #689739);
  background-image: linear-gradient(to bottom, #8ec15b, #689739);
}

.nav-counter-blue {
  background: #3b8de2;
  border: 1px solid #215a96;
  background-image: -webkit-linear-gradient(top, #67a7e9, #2580df);
  background-image: -moz-linear-gradient(top, #67a7e9, #2580df);
  background-image: -o-linear-gradient(top, #67a7e9, #2580df);
  background-image: linear-gradient(to bottom, #67a7e9, #2580df);
}

html十分精简,只有一句话,但是css比较复杂,主要是a标签的position: relative,里面显示消息数量的div设成position:absolute,然后就有了重叠效果。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我扶奶奶过哈登

您的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值