flex box项目宽度缩小为文本

时间:2016-04-07 05:15:25

标签: html css flexbox

此代码尝试缩小单选按钮标签,该标签是{< {3}}标记为"黄色"只是匹配无线电图标右侧的字符串。

目前的问题是span span`也是可点击的。

enter image description here

span' goes too close to the next radio icon that if the mobile user wanting to click the second icon could hit the first radio button by mistake since the
.radio-group {
    background-color: red;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-flow: row;
    -ms-flex-flow: row;
    flex-flow: row;
}

.radio-item {
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-flow: row;
    -ms-flex-flow: row;
    flex-flow: row;
    align-items: baseline;
}

.radio-icon {
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
}

.radio-label {
    background-color: yellow;
    -webkit-flex: 15;
    -ms-flex: 15;
    flex: 15;
}

1 个答案:

答案 0 :(得分:0)

只需在radio-item上使用一些保证金,如下所示。

.radio-item {
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-flow: row;
    -ms-flex-flow: row;
    flex-flow: row;
    align-items: baseline;
    margin-right:30px; /* add margin here */
}

.radio-group {
    background-color: red;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-flow: row;
    -ms-flex-flow: row;
    flex-flow: row;
}

.radio-item {
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-flow: row;
    -ms-flex-flow: row;
    flex-flow: row;
    align-items: baseline;
    margin-right:30px;
}

.radio-icon {
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
}

.radio-label {
    background-color: yellow;
    -webkit-flex: 15;
    -ms-flex: 15;
    flex: 15;
}
<div name="radio">
  <div class="radio-group">
      <label class="radio-item">
        <input class="radio-icon" type="radio" name={{group}} checked={{value}} value={{name}}>
        <span class="radio-label">{{caption}}</span>
      </label>
      <label class="radio-item">
        <input class="radio-icon" type="radio" name={{group}} checked={{value}} value={{name}}>
        <span class="radio-label">{{caption}}</span>
      </label>
  </div>
</div>