如何用css在两个圆圈之间绘制水平线? [英] How to draw a horizontal line between two circles with css?

查看:140
本文介绍了如何用css在两个圆圈之间绘制水平线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在css中的2个圆圈之间绘制水平线?



它必须在屏幕中间显示。



示例:

/ p>



我画了2个圈子, t知道如何连接它们。



#status-buttons a {color:黑色;显示:inline-block; font-size:17px; font-weight:normal; margin-right:0; text-align:center;文字转换:大写; min-width:150px; text-decoration:none;}#status-buttons a:hover {text-decoration:none;}#status-buttons a.active span {color:white;背景:#ACCF5B; box-shadow:rgba(0,0,0,0.792157)3px 3px 3px 0;}#status-buttons span {color:white;背景:#22bacb;显示:块;身高:45px; margin:0 auto 10px; padding-top:20px;宽度:60px;边界半径:50%; box-shadow:rgba(0,0,0,0.792157)3px 3px 3px 0;}

 < div id =status-buttonsclass =text-center> < a href =#/ form / regaloclass =active>< span> 1< / span>步骤1< / a> < a href =#/ form / tusdatos>< span> 2< / span>步骤2< / a>< / div>  

在JSFiddle上展示一个href =http://%20https://jsfiddle.net/nerlijma/s5x2kmmz/ =nofollow>演示

解决方案

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

 #status-buttons {position:relative; / * 1 * / display:inline-block; / * 2 * /}#status-buttons :: after {/ * 3 * / content:;位置:绝对;宽度:50%; z-index:-1; / * 4 * / top:35%;左:25%; border:3px solid#ACCF5B;}#status-buttons a {color:black;显示:inline-block; font-size:17px; font-weight:normal; margin-right:0; text-align:center;文字转换:大写; min-width:150px; text-decoration:none;}#status-buttons a:hover {text-decoration:none;}#status-buttons a.active span {color:white;背景:#ACCF5B; box-shadow:rgba(0,0,0,0.792157)3px 3px 3px 0;}#status-buttons span {color:white;背景:#22bacb;显示:块;身高:45px; margin:0 auto 10px; padding-top:20px;宽度:60px;边界半径:50%; box-shadow:rgba(0,0,0,0.792157)3px 3px 3px 0;}  

 < div id =status-buttonsclass =text-center> < a href =#/ form / regaloclass =active>< span> 1< / span>步骤1< / a> < a href =#/ form / tusdatos>< span> 2< / span>步骤2< / a>< / div>  


  1. 建立最接近定位的祖先的绝对定位。

  2. 使容器只消耗必要的宽度。

  3. 插入伪元素
  4. >
  5. 确保水平线重叠不会出现在圆圈上方


How to draw a horizontal line in between 2 circles in css?

It has to be in the middle of them just as shown in the screenshot.

Example here:

I have drawn the 2 circles, but don't know how to connect them.

#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>

See demo on JSFiddle

解决方案

You can use a pseudo-element to insert an absolutely-positioned border:

#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>

Notes:

  1. Establish nearest positioned ancestor for absolute positioning.
  2. Make container consume only the width necessary.
  3. Insert pseudo element
  4. Ensure that any horizontal line overlap doesn't appear above circles

这篇关于如何用css在两个圆圈之间绘制水平线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆