html - 如何使用 CSS 在两个圆圈之间绘制一条水平线?

标签 html css css-shapes

如何在 CSS 中的两个圆圈之间画一条水平线?

它必须在它们的中间,如屏幕截图所示。

这里的例子:

enter image description here

我画了两个圆圈,但不知道如何连接它们。

#status-buttons a {
  color: black;
  display: inline-block;
  font-size: 17px;
  font-weight: normal;
  margin-right: 0;
  text-align: center;
  text-transform: uppercase;
  min-width: 150px;
  text-decoration: none;
}
#status-buttons a:hover {
  text-decoration: none;
}
#status-buttons a.active span {
  color: white;
  background: #ACCF5B;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
#status-buttons span {
  color: white;
  background: #22bacb;
  display: block;
  height: 45px;
  margin: 0 auto 10px;
  padding-top: 20px;
  width: 60px;
  border-radius: 50%;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
<div id="status-buttons" class="text-center">
  <a href="#/form/regalo" class="active"><span>1</span> Step 1</a>
  <a href="#/form/tusdatos"><span>2</span> Step 2</a>
</div>

参见 demo on JSFiddle

最佳答案

您可以使用伪元素插入绝对定位的边框:

#status-buttons {
  position: relative;          /* 1 */
  display: inline-block;       /* 2 */
}
#status-buttons::after {       /* 3 */
  content: "";
  position: absolute;
  width: 50%;
  z-index: -1;                 /* 4 */
  top: 35%;
  left: 25%;
  border: 3px solid #ACCF5B;
}
#status-buttons a {
  color: black;
  display: inline-block;
  font-size: 17px;
  font-weight: normal;
  margin-right: 0;
  text-align: center;
  text-transform: uppercase;
  min-width: 150px;
  text-decoration: none;
}
#status-buttons a:hover {
  text-decoration: none;
}
#status-buttons a.active span {
  color: white;
  background: #ACCF5B;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
#status-buttons span {
  color: white;
  background: #22bacb;
  display: block;
  height: 45px;
  margin: 0 auto 10px;
  padding-top: 20px;
  width: 60px;
  border-radius: 50%;
  box-shadow: rgba(0, 0, 0, 0.792157) 3px 3px 3px 0;
}
<div id="status-buttons" class="text-center">
  <a href="#/form/regalo" class="active"><span>1</span> Step 1</a>
  <a href="#/form/tusdatos"><span>2</span> Step 2</a>
</div>

注意事项:

  1. Establish nearest positioned ancestor for absolute positioning.
  2. 让容器只占用必要的宽度。
  3. 插入伪元素
  4. 确保任何水平线重叠不会出现在圆圈上方

关于html - 如何使用 CSS 在两个圆圈之间绘制一条水平线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40077096/

相关文章:

用于插入的 php 数组内爆

javascript - 禁用的选中复选框未发送到表单提交时的模型

html - 从内侧绕箭头

php - 从mysql查询结果中填写表单的字段

html - <div> 覆盖背景图片

javascript - 在 mouseenter(悬停)上,显示和隐藏(切换)子元素

jquery - 我如何在 jQuery Mobile 默认导航栏中有一个更大的中心底部导航栏按钮?

html - 用 CSS 在标题后画线

html - 如何在不使用背景图像的情况下使用 css3 在 html div 中制作菱形...?

php - Wordpress嵌入式视频问题