CSS3实现左上角或右上角显示提醒圆点的示例代码
(编辑:jimmy 日期: 2025/10/28 浏览:3 次 )
效果图(如果想要三角形请点击这里):
代码:
<html>
<head>
<style type="text/css">
.message_s {
position: relative;
cursor: pointer;
}
.message_s:after {
position: absolute;
content: "";
/*以下内容可以根据实际需要进行调整 -----start------*/
top: 0px;
left: -13px; /*改成:right: -13px; 圆点显示在右侧*/
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #e98b7f;
/*-----end------*/
}
div {
height: 30px;
border: 1px #000 solid;
width: 300px;
line-height: 30px;
padding: 0px 0px 0px 15px;
}
</style>
<script>
function clickAction()
{
console.log("天不生我leader,键道万古长如夜!");
}
</script>
</head>
<body>
<div>
<span class="message_s" onclick="clickAction()"></span>
剑开天门
</div>
</body>
</html>
附录:下面看下左上角实现红色三角号标识
左上角实现红色三角号标识,如图
利用伪类实现,position和transform、border属性为重点。
位置调整修改top和left的值即可。
<html>
<head>
<title> New Document </title>
<style>
div {
background-color: #f4f4f4;
padding: 20px;
}
.message_s {
position: relative;
}
.message_s:after {
position: absolute;
top: -25px;
display: block;
width: 0;
height: 0;
border: 16px solid transparent;
content: "";
-webkit-transform: rotate(45deg);
}
.message_s:after {
left: -25px;
z-index: 0;
border-right-color: red;
}
</style>
</head>
<body>
<div>
<span class="message_s">Internet Explorer 10、Firefox、Opera 支持 transform 属性。Internet Explorer 9 支持替代的 -ms-transform 属性(仅适用于 2D 转换)。Safari 和 Chrome 支持替代的 -webkit-transform 属性(3D 和 2D 转换)。Opera 只支持 2D 转换。</span>
</div>
</body>
</html>
下一篇:详解CSS边距重叠与解决方案探究

