html - 如何在 CSS 中创建编号标记?

标签 html css

我尝试编写 CSS 代码样式来生成如下所示的编号标记

Outcome of numbering marker

但尾部圆圈的形状看起来不正确。

我在这里尝试使用 CSS 代码:

.comment-icon {
  width: 30px;
  height: 30px;
  border-radius: 100%;
  border: 2.45px solid #e7ad56;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
}

.comment-icon:before {
  position: absolute;
  content: "";
  width: 15px;
  height: 16px;
  border-top: 2.45px solid #e7ad56;
  top: 20px;
  left: -6px;
  transform: rotate(286deg);
}

.comment-icon:after {
  position: absolute;
  content: "";
  width: 15px;
  height: 16px;
  border-bottom: 2.45px solid #e7ad56;
  top: 16px;
  left: -13px;
  transform: rotate(325deg);
}
<div class="comment-icon">1</div>

我已经尝试调整 :before:after 边界定位但根本没有得到正确的点。

请问有人可以帮忙弄这个形状吗?谢谢。

最佳答案

您可以使用 :before:after 选择器来创建箭头并调整其位置。

.comment-icon {
  width: 30px;
  height: 30px;
  border-radius: 100%;
  border: 2.45px solid #e7ad56;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
}

.comment-icon:before {
  position: absolute;
  content: ""; 
  top: 24px;
  left: -9px;  
  width: 0; 
  height: 0; 
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;  
  border-top: 15px solid #e7ad56;
  transform: rotate(50deg);
}

.comment-icon:after {
  position: absolute;
  content: ""; 
  top: 24px;
  left: -5px;  
  width: 0; 
  height: 0; 
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;  
  border-top: 12px solid #fff;
  transform: rotate(50deg);
}
<div class="comment-icon">1</div>

关于html - 如何在 CSS 中创建编号标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68175619/

相关文章:

html - 复选框垂直对齐

CSS Flip 跨浏览器功能

php - Blade View 不在 laravel 中呈现

HTML5/CSS3 : 100% height layout for mobile with two divs as buttons and no overflow

javascript - 根据scroll设置div的位置

html - 页面在 chrome/firefox 中工作正常但在 IE 中不工作

html - 为什么窗口最小化时div在另一个div之上

html - 导航栏打破照片幻灯片的边距问题

html - 单击更改背景图像

Javascript,将事件绑定(bind)到 div 标签时出现问题