html - 使用::before 创建围绕圆的线

标签 html css

我正在尝试使用伪创建类似的东西:

enter image description here

但不确定我目前采用的方法是否是解决此问题的最佳方法?

.divider{
  display: flex;
  flex-direction: column;
}
.line1::before{
  content: '';
  /*position: absolute;*/
  display: block;
  width: 4em;
  height: .2em;
  background: red;
  transform: rotate(90deg);
}
.circle::before{
   content: '';
   display: inline-block;
   width: 15px;
   height: 15px;
   -moz-border-radius: 7.5px;
   -webkit-border-radius: 7.5px;
   border-radius: 7.5px;
   background-color: red;
}
<div class="divider">
  <div class="line1"></div>
  <div class="circle"></div>
  <div class="line2"></div>
</div>

你会使用伪元素创建这样的东西吗?如果是这样,我怎样才能让它看起来像图像中的那个?

最佳答案

这很简单,只需要在垂直和水平中间放置元素即可:

.wrapper {
  width: 100px;
  height: 200px;
  background-color: rgba(30, 50, 80, .3);
  position: relative;
}

.wrapper div {
  border-radius: 50%;
  background-color: blue;
  position: absolute;
  top: 50%;
  margin-top: -25px;
  left: 50%;
  margin-left: -25px;
  width: 50px;
  height: 50px;
  background: center center no-repeat url(https://static.thenounproject.com/png/19279-200.png) blue;
  background-size: 30px;
}

.wrapper:before,
.wrapper:after {
  content: '';
  display: block;
  width: 2px;
  height: 60px;
  background: blue;
  position: absolute;
  left: 49px;
}

.wrapper:before {
  top: 0;
}

.wrapper:after {
  bottom: 0;
}
<div class="wrapper"><div></div></div>

关于html - 使用::before 创建围绕圆的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57002269/

相关文章:

html - 添加颜色 block 作为 <li> 元素符号

jquery - 在 JQuery 中通过 SlideDown 和 SlideUp 更改其他照片的位置

javascript - FF 3.6 中不显示搜索字段文本?

javascript - 如何动态对齐图例元素?

iOS 为所有网络浏览器支持录制的视频

html - CSS::before 伪元素行高?

javascript - 按钮在 iPhone 上的 Safari 中不起作用

html - 如何使 div 固定以使滚动文本不会越过它?

html - 仅使用 CSS3/HTML5 绘制图像的标准方法 - 案例 : HTML 5 logo ?

html - 我的图片是水平堆叠的,我不知道我是怎么做到的?