您好我正在尝试使用css3创建一个带有响应圆圈的div。
我尝试做http://codepen.io/bookcasey/pen/cEntL
的例子在上面的示例中,我想让它响应,使得圆圈尺寸不会改变,但如果宽度增加,我希望第一个和最后一个圆圈位于UL的左侧和右侧,其他圆圈位于两者之间,距离相等。圆圈可以增加或减少最少是两个圆圈和一条线。
答案 0 :(得分:5)
您可以使用Justify the last line of a div?的解决方案使其达到全宽。
伪造具有绝对定位伪元素的行。
ul {
text-align: justify;
position: relative;
overflow: hidden;
}
ul:before, .active:after {
content: '';
width: 100%;
border: 2px solid dodgerblue;
position: absolute;
top: 1em;
margin-top: -2px;
z-index: -1;
}
.active:after {
border-color: lightblue;
}
ul:after {
content: "";
display: inline-block;
width: 100%;
}
li {
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border-radius: 50%;
background: dodgerblue;
margin: 0 1em;
display: inline-block;
color: white;
}
.active ~ li {
background: lightblue;
}
body {
font-family: sans-serif;
padding: 2em;
}
答案 1 :(得分:0)
我通过使用浮点数解决,在元素之前作为圆圈,然后作为连接:
li {
width: 14%;
text-align: center;
line-height: 2em;
float: left;
color: white;
position: relative;
}
li:before{
content: '';
position: absolute;
top: 0;
left: calc(50% - 1em);
width: 2em;
height: 2em;
border-radius: 1em;
background: dodgerblue;
z-index: -1;
}
li:after{
content: '';
position: absolute;
top: .9em;
left: calc(50% + 1em);
width: 100%;
height: .2em;
background: dodgerblue;
z-index: -1;
}
答案 2 :(得分:0)
如果你想在每个数字下面添加一个文本块,我也会继续这样做! Check it out on CodePen
HTML
<ul>
<li><span class="marker-number">1</span> <span class="marker-text">Select Car</span></li>
<li class="active"><span class="marker-number">2</span> <span class="marker-text">Questions</span></li>
<li><span class="marker-number">3</span> <span class="marker-text">Problems</span></li>
<li><span class="marker-number">4</span> <span class="marker-text">Inspection</span></li>
<li><span class="marker-number">5</span> <span class="marker-text">Solution</span></li>
</ul>
<强> CSS 强>
ul {
text-align: justify;
position: relative;
overflow: hidden;
}
ul:before, .active:after {
content: '';
width: 100%;
border: 2px solid #21a2d1;
position: absolute;
top: 1em;
margin-top: -6px;
z-index: -1;
}
.active:after {
border-color: #b7b7b7;
}
ul:after {
content: "";
display: inline-block;
width: 100%;
}
li {
width: 1.5em;
height: 1.5em;
text-align: center;
line-height: 1.7em;
border-radius: 50%;
background: #21a2d1;
margin: 0 1em;
display: inline-block;
color: white;
font-size: 1em;
}
.marker-number {
font-size: 14px;
}
li.active {
background: #04497b;
}
.active ~ li {
background: #b7b7b7;
}
span.marker-text {
color: #7d7d7d;
font-size: 12px;
line-height: 16px;
width: 70px;
display: block;
margin-left: -21px;
margin-top: 2px;
font-style: italic;
font-family: Arial;
}