[英]horizontal line between circles with transparent background
I'm trying to draw a horizontal line between empty circles (no background), How can I draw a line from one circle to other to match exactly without entering the other circle or not reach it? 我试图在空心圆之间绘制一条水平线(没有背景),如何从一个圆到另一个圆绘制一条线以完全匹配而不进入另一个圆或不到达它?
I did the sample using codepen 我使用codepen做了样本
#wizard { background-color: #eee; display: inline-block; padding: 15px; } #wizard .step { display: inline-block; width: 40px; height: 40px; background-color: transparent; border: 1px solid #000; border-radius: 50%; text-align: center; padding: 2px; margin-right: 3em; margin-left: 3em; position: relative; } #wizard .step:after { content: ""; display: block; height: 1px; background-color: #000; position: absolute; left: auto; right: -100%; width: 100%; top: 50%; } #wizard .step:last-child:after { display: none; } #wizard .step span { padding: 11px; display: block; }
<div id="wizard"> <div class="step active"> <span>1</span> </div> <div class="step"> <span>2</span> </div> <div class="step"> <span>3</span> </div> </div>
Since your margin-right
and margin-left
are both 3em
, try using 6em
instead of 100%
由于您的margin-right
和margin-left
都是3em
,尝试使用6em
而不是100%
left:auto;
right:-6em;
width:6em;
That leaves a little space, but you can tweak it: 留下一点空间,但你可以调整它:
right:-6.3em;
width:6.3em;
If you're going to absolutely position your #wizard .step::after
pseudo-element, you need to know 2 things: 如果你要绝对定位#wizard .step::after
伪元素,你需要知道两件事:
You can see where it should begin, given that your #wizard .step
has a border of 1px
, a padding of 2px
and a content width of 40px
. 你可以看到它应该从哪里开始,因为#wizard .step
的边框为1px
,填充为2px
,内容宽度为40px
。
1px
+ 2px
+ 40px
+ 2px
+ 1px
= 46px
1px
+ 2px
+ 40px
+ 2px
+ 1px
= 46px
So your position styles need to include left: 46px
: 所以你的职位风格需要包括left: 46px
:
#wizard .step::after {
position: absolute;
top: 50%;
left: 46px;
}
As for how long it needs to be, it needs to span the margin-right
of the current #wizard .step
and then the margin-left
of the next #wizard .step
. 至于它需要多长时间,它需要跨越当前#wizard .step
margin-right
#wizard .step
,然后是下一个#wizard .step
margin-left
#wizard .step
。
Since these are both 3em
, you can give it your #wizard .step::after
pseudo-element a width
of 6em
. 由于这些都是3em
,你可以给它你的#wizard .step::after
伪元素width
为6em
。
Putting it all together: 把它们放在一起:
#wizard { background-color: #eee; display:inline-block; padding:15px; } #wizard .step { display: inline-block; width: 40px; height: 40px; background-color: transparent; border: 1px solid #000; border-radius: 50%; text-align: center; padding: 2px; margin-right: 3em; margin-left: 3em; position: relative; } #wizard .step::after { content: ''; display: block; position: absolute; top: 50%; left: 46px; width: 6em; height: 1px; background-color: #000; } #wizard .step:last-child::after { display:none; } #wizard .step span { padding: 11px; display: block; }
<div id="wizard"> <div class="step active"> <span>1</span> </div> <div class="step"> <span>2</span> </div> <div class="step"> <span>3</span> </div> </div>
NB It's really not clear to me why, but though the result from the approach above should be flawless, the actual result includes tiny gaps - giving every impression of being from a 1950s text-book. NB我真的不清楚为什么,但是虽然上述方法的结果应该是完美的,但实际结果包括微小的差距 - 从20世纪50年代的教科书中给出每一个人的印象。
If you want to eliminate these gaps, use the following style declarations, instead: 如果要消除这些间隙,请使用以下样式声明:
#wizard .step::after {
left: 45px;
width: 6.3em;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.