html - Radio button inside label width issue -


i have custom radio buttons , try display multiple radio buttons in 1 line. currently, code works fine issue adding fixed width label in case width:50px;.

if text longer... text overlaps next radio button. there way can avoid having fixed widths? function calc() does't seem in situation.

i also, tried using min-width instead of width.

* {    box-sizing: border-box;  }  input[type="radio"] {    display: none;    cursor: pointer;  }  label {    cursor: pointer;    display: inline-block;    width: 50px;    position: relative;  }  .radio span.custom > span {    margin-left: 22px;  }  .radio .custom {    background-color: #fff;    border: 1px solid #ccc;    border-radius: 3px;    display: inline-block;    height: 20px;    left: 0;    position: absolute;    top: 0;    width: 20px;  }  .radio input:checked + .custom:after {    background-color: #0574ac;    border-radius: 100%;    border: 3px solid #fff;    content: "";    display: block;    height: 12px;    position: absolute;    top: 0;    width: 12px;  }  .radio input + .custom {    border-radius: 100%;  }  .checkbox input:checked .custom {    background-color: blue;    border-color: blue;  }
<label class="radio">    <input type="radio">    <span class="custom"><span>one</span></span>  </label>

update:

i need text inside <span class="custom"> tag. don't have have inner span tag there though

jsfiddle demo

try using :after pseudo element construct rounded radio button. , change .custom display: inline takes content width. add white-space: nowrap span in-order take full width of text without breaking.

* {    box-sizing: border-box;  }    input[type="radio"] {    display: none;    cursor: pointer;  }    label {    cursor: pointer;    min-width: 50px;    display:inline-block;    position:relative;  }    .radio span.custom > span {    margin-left: 24px;    margin-right: 10px;    display: inline-block;    white-space: nowrap;    line-height: 22px;  }    .radio .custom {      display: inline;  }    .radio .custom:after{     content: '';    height: 20px;    left: 0;    top: 0;    width: 20px;    background-color: #fff;    border: 1px solid #ccc;    border-radius: 3px;    position: absolute;  }    .radio input:checked + .custom:before {      background-color: #0574ac;      border-radius: 100%;      border: 3px solid #fff;      content: "";      display: block;      height: 12px;      position: absolute;      top: 2px;      width: 12px;      z-index: 1;      left: 2px;  }    .radio input + .custom:after {    border-radius: 100%;  }    .checkbox input:checked .custom {    background-color: blue;    border-color: blue;  }
<label class="radio">    <input type="radio">    <span class="custom"><span>one</span></span>  </label>    <label class="radio">    <input type="radio">    <span class="custom"><span>two (longer text)</span></span>  </label>    <label class="radio">    <input type="radio">    <span class="custom"><span>three (another longer text)</span></span>  </label>    <label class="radio">    <input type="radio">    <span class="custom"><span>four</span></span>  </label>


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -