input[type=radio] {
position: absolute;
visibility: hidden;
display: none;
}
label {
flex: 1 0 auto;
background-color: white;
text-align: center;
color: dimgray;
cursor: pointer;
font-weight: bold;
user-select: none;
padding: 5px;
width: 60px;
transition: background 0.2s, color 0.2s;
}
input[type=radio]:checked + label{
color: White;
background: dimgrey;
&:hover {
color: White;
background: dimgrey;
}
}
input[type=radio] + label:hover {
color: white;
background-color: lightgrey;
}
label + input[type=radio] + label {
border-left: 0.5px solid lightgrey;
}
.radio-group {
display: flex;
flex-wrap: wrap;
max-width: max-content;
align-items: stretch;
border: 0.5px solid dimgrey;
}

<form>
<div class="radio-group flexbox">
<input type="radio" id="alle" value="alle" name="selector" checked><label for="alle">Alle</label
><input type="radio" id="aktiv" value="aktiv" name="selector" ><label for="aktiv">Aktive</label
><input type="radio" id="inaktiv" value="inaktiv" name="selector"><label for="inaktiv">Inaktive</label>
</div>
</form>
&#13;
我怎样才能实现这一目标?我尝试调整柔性包装,方向,流动等。无法使其按照我想要的方式工作。
编辑:我希望它看起来像默认情况下的代码片段(标签水平排列)。我只是希望它在窗口缩小时用第一个标签包装自己的行和下面的另外两个标签。
答案 0 :(得分:0)
请检查以下代码。谢谢
input[type=radio] {
position: absolute;
visibility: hidden;
display: none;
}
label {
flex: 1 0 auto;
background-color: white;
text-align: center;
color: dimgray;
cursor: pointer;
font-weight: bold;
user-select: none;
padding: 5px;
width: 60px;
transition: background 0.2s, color 0.2s;
}
input[type=radio]:checked + label{
color: White;
background: dimgrey;
&:hover {
color: White;
background: dimgrey;
}
}
input[type=radio] + label:hover {
color: white;
background-color: lightgrey;
}
label + input[type=radio] + label {
border-left: 0.5px solid lightgrey;
}
.radio-group {
display: flex;
flex-wrap: wrap;
max-width: max-content;
align-items: stretch;
border: 0.5px solid dimgrey;
}
.radio-group.flexbox > label:nth-child(2) {
width: calc( 100% - 12px ) !IMPORTANT;
}
<form>
<div class="radio-group flexbox">
<input type="radio" id="alle" value="alle" name="selector" checked><label for="alle">Alle</label
><input type="radio" id="aktiv" value="aktiv" name="selector" ><label for="aktiv">Aktive</label
><input type="radio" id="inaktiv" value="inaktiv" name="selector"><label for="inaktiv">Inaktive</label>
</div>
</form>