如何将此圈子与css(或js / jquery)连接起来,以便在屏幕较小时它可以响应并且线条不重叠。此外,我试图在整个容器后面排队,但由于我的圈子需要透明,所以线条总是在圈子后面:
这是唯一一条线不在每个圆圈后面的方式。但我不知道如何使它不重叠,我需要我的线从一个边界到另一个边界。 此外,当我减小宽度时,线条重叠并落后于圆圈。
演示:http://codepen.io/riogrande/pen/jqVKBb
css:
.flex-container {
padding: 0;
margin: 0;
list-style: none;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.flex-container .flex-item {
background: transparent;
width: 50px;
height: 50px;
margin: 5px;
line-height: 50px;
color: #ffefbd;
font-weight: bold;
font-size: 22px;
text-align: center;
border: 6px solid #ffefbd;
border-radius: 50%;
position: relative;
}
.flex-container .flex-item:after {
width: 100%;
border-top: 6px solid #ffefbd;
content: '';
display: block;
position: absolute;
left: 100%;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.flex-container .flex-item:before {
width: 100%;
border-top: 6px solid #ffefbd;
content: '';
display: block;
position: absolute;
right: 100%;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.flex-container .flex-item:last-child:after {
display: none;
}
.flex-container .flex-item:first-child:before {
display: none;
}
html:
<ul class="flex-container space-between">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
<li class="flex-item">7</li>
</ul>
答案 0 :(得分:3)
我使用简单的标记和CSS提出了这个解决方案。 Codepen包含动画示例,以防这是一种进步的事情。
Codepen:http://codepen.io/jpecor-pmi/pen/GZNPWO
HTML
<section id="circles">
<div data-num="1"></div>
<div data-num="2"></div>
<div data-num="3"></div>
<div data-num="4"></div>
<div data-num="5"></div>
<div data-num="6"></div>
<div data-num="7"></div>
</section>
CSS
/*
@circle-diameter: 50px;
@circle-count: 7;
@border-width: 6px;
@border-color: #ffefbd;
*/
/* circle containers */
#circles > div {
background: transparent;
font-weight: bold;
float: left;
height: 50px; /* @circle-diameter */
position: relative;
width: calc((100% - 50px) / 6 - .1px); /* (100% - @circle-diameter) / (@circle-count - 1) - 0.1px for IE :( */
}
/* circle */
#circles > div::before {
border: 6px solid #ffefbd; /* @border-thickness solid @border-color */
border-radius: 25px; /* @circle-diameter / 2 */
color: #ffefbd;
content: attr(data-num); /* value from data-num attribute */
display: block;
float: left;
font: 21px sans-serif;
height: 50px; /* @circle-diameter */
line-height: 38px;
text-align: center;
width: 50px; /* @circle-diameter */
}
/* line */
#circles > div::after {
background: #ffefbd; /* @border-color */
content: '';
display: block;
height: 6px; /* @border-thickness */
position: absolute;
right: -1px; /* removes gap between circle and line */
top: calc(50% - 3px); /* 50% - (@border-thickness / 2) */
width: calc(100% - 48px); /* 100% - (@circle-diameter - 2px) */
}
/* first circle */
#circles > div:first-child {
width: 50px; /* @circle-diameter */
}
#circles > div:first-child::after {
display: none; /* hide line for first circle */
}
/* reset */
#circles,
#circles > div,
#circles > div::before,
#circles > div::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
答案 1 :(得分:0)
好的,所以我设法只使用CSS。解决方案是将圆圈包装成宽度为&#34; 100%/ n&#34;在哪里&#34; n&#34;是您要显示的圈数。所以你需要知道有多少。在我的例子中有7个圆圈。在那些div中,我放了一个叫做圆圈的div。此div具有圆形样式,并且其位于父div的中心位置margin: 0 auto;
。使用伪元素我创建的线条需要非常大(长度),所以不会有任何漏洞。然后使用以下内容更正重叠:position: relative;
和overflow: hidden;
。圆圈是透明的,但线条永远不会与其他div交叉。 Hacky但是很有效。
完整代码:http://codepen.io/riogrande/pen/reWQeK
css:
* {
box-sizing: border-box;
}
.progress {
.sevent{
width: (100/7) * 1%;
text-align: center;
float: left;
background:lightblue;
position: relative;
overflow: hidden;
.circle {
width: 60px;
height:60px;
margin: 0 auto;
border: 6px solid red;
border-radius:50%;
position: relative;
&:before {
content: "";
width: 300%;
border-top: 6px solid red;
position: absolute;
right: 100%;
top: 50%;
transform:translateY(-50%);
}
&:after {
content: "";
width: 300%;
border-top: 6px solid red;
position: absolute;
left: 100%;
top: 50%;
transform:translateY(-50%);
}
}
&:last-child {
.circle {
&:after {
display: none;
}
}
}
&:first-child {
.circle {
&:before {
display: none;
}
}
}
}
}
HTML:
<div class="progress">
<div class="sevent">
<div class="circle">
1
</div>
</div>
<div class="sevent">
<div class="circle">
1
</div>
</div>
<div class="sevent">
<div class="circle">
1
</div>
</div>
<div class="sevent">
<div class="circle">
1
</div>
</div>
<div class="sevent">
<div class="circle">
1
</div>
</div>
<div class="sevent">
<div class="circle">
1
</div>
</div>
<div class="sevent">
<div class="circle">
1
</div>
</div>
</div>