2 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個贊
仍然不確定你的期望是什么......所以我用<label>
s 和隱藏的復(fù)選框做了一個 4 步 Whatchamacallit。向前單擊它們,它們就會發(fā)生變化。如果向后走,則需要按順序進(jìn)行。做出這種行為是為了不存在任何間隙。
這種純 CSS 動態(tài)行為可以通過以下方式實(shí)現(xiàn):
通用兄弟組合器
標(biāo)簽標(biāo)簽
[for]
屬性:checked
CSS偽類justify-content: space-between;
演示
:root,
body {
? width: 100%;
? height: 100%;
? padding: 20px 10px;
? font: 400 5vw/1 Consolas, monospace;
}
main {
? display: flex;
? justify-content: start;
? align-items: center;
? overflow: hidden;
? margin: 0 30px 0 -30px;
}
.box {
? display: flex;
? flex-flow: row nowrap;
? justify-content: space-between;
? align-items: center;
? width: 90%;
? height: 5vw;
? line-height: 1;
? margin: 0 auto;
? padding: 0;
? background: linear-gradient(180deg, rgba(255, 255, 255, 0) calc(50% - 1px), rgba(0, 0, 0, 1) calc(50%), rgba(255, 255, 255, 0) calc(50% + 1px));
}
.s {
? position: relative;
? display: inline-block;
? width: 5vw;
? height: 5vw;
? margin: 0;
? padding: 0;
? color: #000;
? background: #fff;
? outline: 2px solid #000;
? text-align: center;
}
#s1 {
? align-self: start;
? order: 4;
}
#s2 {
? order: 3;
}
#s3 {
? order: 2;
}
#s4 {
? align-self: end;
? order: 1;
}
.c {
? display: none;
}
.c:checked~.s {
? color: #fff;
? background: #000;
}
.c,
.s {
? cursor: pointer;
}
<main>
? <section class='box'>
? ? <input id='c1' class='c' type='checkbox'>
? ? <label id='s1' class='s' for='c1'>4</label>
? ? <input id='c2' class='c' type='checkbox'>
? ? <label id='s2' class='s' for='c2'>3</label>
? ? <input id='c3' class='c' type='checkbox'>
? ? <label id='s3' class='s' for='c3'>2</label>
? ? <input id='c4' class='c' type='checkbox'>
? ? <label id='s4' class='s' for='c4'>1</label>
? </section>
</main>

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個贊
對于三個項目,您需要更改.bullet.completed::after
width
為calc(200% - 21px);
。根據(jù)項目數(shù)量更改父級的類:https://jsfiddle.net/bortao/buw28o53/
- 2 回答
- 0 關(guān)注
- 204 瀏覽
添加回答
舉報