如何使用 CSS 创建通知按钮?
cssweb developmentfront end technology更新于 2025/10/5 6:04:17
以下是使用 CSS 创建通知按钮的代码 −
示例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
font-family: monospace,serif,sans-serif;
}
.notificationContainer {
margin: 20px;
background-color: rgb(254, 255, 171);
color: black;
text-decoration: none;
padding: 15px 26px;
font-size: 32px;
position: relative;
display: inline-block;
border-radius: 2px;
border:2px solid black;
}
.notificationContainer:hover {
background: rgb(43, 8, 138);
color:white;
}
.notificationContainer .notificationBadge {
position: absolute;
top: -10px;
right: -10px;
padding: 5px 10px;
border-radius: 50%;
background-color: rgb(0, 170, 51);
color: white;
}
</style>
</head>
<body>
<h1>Notification Button Example</h1>
<a href="#" class="notificationContainer">
<span>Messages</span>
<span class="notificationBadge">99+</span>
</a>
</body>
</html>
输出
上述代码将产生以下输出 −

当鼠标悬停在消息按钮上方时,颜色将发生如下变化 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

