gpt4 book ai didi

css - 如何防止单选按钮断行?

转载 作者:行者123 更新时间:2023-11-28 04:06:33 25 4
gpt4 key购买 nike

对于我正在创建的表单,我使用 css 将单选按钮显示为切换开关。

但是它根本没有响应。在移动设备上查看时,“比例”1-5 被分成几 block 。我的目标是响应性地改变比例的 with 而不是它分解。

不知何故,我似乎无法弄明白。

这是代码:http://jsfiddle.net/7byse1vk/

.toggle__label {
transition: all .25s ease;
display: inline-block;
border-radius: 5px;
background-color: #878787;
cursor: pointer;
padding: 0 30px;
min-width: 100px;
height: 48px;
line-height: 48px;
color: #a7a6ae;
text-align: center;
}

非常感谢!

最佳答案

您可以在父级上使用 display: flex;,从标签中删除 min-width(否则会使它们每个至少 160px 宽,太宽了对于移动设备),并将它们设置为 flex-grow: 1,以便它们流畅地填充父级。

body {
padding: 20px;
}

.toggle {
margin-bottom: 20px;
}

.row {
display: flex;
}

.toggle__label {
transition: all .25s ease;
border-radius: 5px;
background-color: #878787;
cursor: pointer;
padding: 0 30px;
height: 48px;
line-height: 48px;
color: #a7a6ae;
text-align: center;
flex-grow: 1;
}

.toggle__input:checked + .toggle__label {
background-color: #e5702a;
color: white;
}

.toggle__label--left {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

.toggle__label--middle {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
margin-left: -4px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}

.toggle__label--right {
margin-left: -4px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}

.toggle__input {
position: absolute;
left: -99999px;
}

label {
padding: 0.4em 2em 0.4em 0;
}

.toggle-btn-grp {
margin: 3px 0;
}

.toggle-btn {
text-align: centre;
margin: 5px 2px;
padding: 0.4em 3em;
color: #000;
background-color: #FFF;
border-radius: 10px;
display: inline-block;
border: solid 1px #CCC;
cursor: pointer;
}

.toggle-btn-grp.joint-toggle .toggle-btn {
margin: 5px 0;
padding: 0.4em 2em;
border-radius: 0;
border-right-color: white;
}

.toggle-btn-grp.joint-toggle .toggle-btn:first-child {
margin-left: 2px;
border-radius: 10px 0px 0px 10px;
}

.toggle-btn-grp.joint-toggle .toggle-btn:last-child {
margin-right: 2px;
border-radius: 0px 10px 10px 0px;
border-right: solid 1px #CCC;
}

.toggle-btn:hover {
border: solid 1px #a0d5dc !important;
background: #f1fdfe;
}

.toggle-btn.success {
background: lightgreen;
border: solid 1px green !important;
}

.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
}


/* CSS only version */

.toggle-btn-grp.cssonly * {
width: 140px;
height: 30px;
line-height: 30px;
}

.toggle-btn-grp.cssonly div {
display: inline-block;
position: relative;
margin: 5px 2px;
}

.toggle-btn-grp.cssonly div label {
position: absolute;
z-index: 0;
padding: 0;
text-align: center;
}

.toggle-btn-grp.cssonly div input {
position: absolute;
z-index: 1;
cursor: pointer;
opacity: 0;
}

.toggle-btn-grp.cssonly div:hover label {
border: solid 1px #a0d5dc !important;
background: #f1fdfe;
}

.toggle-btn-grp.cssonly div input:checked + label {
background: lightgreen;
border: solid 1px green !important;
}
<div class="row">
<input class="toggle__input" id="option-1" type="radio" name="input4" value="1">
<label class="toggle__label toggle__label--left" for="option-1">1</label>

<input checked="true" class="toggle__input" id="option-2" type="radio" name="input4" value="2">
<label class="toggle__label toggle__label--middle" for="option-2">2</label>

<input class="toggle__input" id="option-3" type="radio" name="input4" value="3">
<label class="toggle__label toggle__label--middle" for="option-3">3</label>

<input class="toggle__input" id="option-4" type="radio" name="input4" value="4">
<label class="toggle__label toggle__label--middle" for="option-4">4</label>

<input class="toggle__input" id="option-5" type="radio" name="input4" value="5">
<label class="toggle__label toggle__label--right" for="option-5">5</label>
</div>

关于css - 如何防止单选按钮断行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42933760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com