当前位置:首页 > CSS

css如何制作未读图标

2026-04-01 01:23:53CSS

使用伪元素和计数器

在CSS中,可以利用伪元素和计数器创建未读图标。通过::after::before伪元素添加数字标记,结合counter属性动态显示未读数量。

.unread-icon {
    position: relative;
    display: inline-block;
    width: 24px;
    height: 24px;
    background-color: #ccc;
    border-radius: 50%;
}

.unread-icon::after {
    content: attr(data-count);
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: red;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

使用绝对定位和动画

通过绝对定位将未读标记固定在右上角,并添加动画效果增强视觉提示。可以使用transform@keyframes实现脉冲动画。

.unread-badge {
    position: relative;
    display: inline-block;
}

.unread-badge::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 8px;
    background-color: red;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

使用Flex布局和动态内容

结合Flex布局和动态内容属性attr(),可以灵活控制未读标记的位置和样式。适用于需要动态更新未读数量的场景。

.notification {
    display: flex;
    align-items: center;
    gap: 8px;
}

.notification-count {
    min-width: 20px;
    padding: 2px 6px;
    background-color: red;
    color: white;
    border-radius: 10px;
    font-size: 12px;
    text-align: center;
}

使用CSS变量和自定义属性

通过CSS变量实现未读标记的颜色和大小动态调整,增强可维护性。适用于主题切换或响应式设计。

:root {
    --unread-color: red;
    --unread-size: 16px;
}

.unread-indicator {
    position: relative;
}

.unread-indicator::before {
    content: "";
    position: absolute;
    top: -4px;
    right: -4px;
    width: var(--unread-size);
    height: var(--unread-size);
    background-color: var(--unread-color);
    border-radius: 50%;
}

响应式设计适配

针对不同屏幕尺寸调整未读标记的大小和位置,使用媒体查询确保在不同设备上显示效果一致。

css如何制作未读图标

.unread-marker {
    position: relative;
    width: 32px;
    height: 32px;
}

.unread-marker::after {
    content: attr(data-count);
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    font-size: 12px;
}

@media (max-width: 600px) {
    .unread-marker::after {
        width: 16px;
        height: 16px;
        font-size: 10px;
    }
}

标签: 读图css
分享给朋友:

相关文章

css制作箭头

css制作箭头

使用 CSS 边框制作箭头 通过调整元素的 border 属性,利用透明边框和实色边框的组合生成箭头。例如,创建一个向右的箭头: .arrow-right { width: 0; hei…

css 在线制作

css 在线制作

CSS 在线制作工具推荐 以下是一些实用的在线 CSS 工具,可用于快速生成、编辑和优化 CSS 代码: CSS 生成器 CSS3 Generator(如css3generator.com):…

淘宝css导航栏制作

淘宝css导航栏制作

淘宝CSS导航栏制作 制作类似淘宝的导航栏需要关注几个关键点:结构清晰、响应式设计、悬停效果以及图标使用。以下是具体实现方法: HTML结构 <div class="nav-container…

css制作圆形

css制作圆形

使用 border-radius 属性 通过设置 border-radius 为 50%,可以将元素变为圆形。此方法适用于正方形元素,确保宽度和高度相等。 .circle { width: 10…

css制作表单

css制作表单

创建基本表单结构 使用HTML的<form>标签作为表单容器,内部包含输入字段、标签和提交按钮。表单元素通常需要<label>关联以提高可访问性。 <form>…

css制作页面

css制作页面

使用CSS制作页面的基本方法 CSS(层叠样式表)用于控制网页的样式和布局。通过CSS可以实现页面元素的定位、颜色、字体、间距等视觉效果。 HTML结构基础 在开始CSS之前,需要先构建HTML结构…