Bootstrap 4样式单选按钮

时间:2018-09-11 15:18:01

标签: css radio-button bootstrap-4 styling

我正在尝试为Bootstrap 4单选按钮设置样式,并且我有1个JS Fiddle,其单选按钮的样式如下:

http://jsfiddle.net/Rick1107/zbeqLmuv

.radio {
  display: inline-block;
  text-align: center;
  padding: 0.5rem;
}

.radio label {
  display: inline-block;
  margin-top: 0rem;
}

.radio label {
  display: inline-block;
  vertical-align: middle;
  position: relative;
  /*   padding-left: 5px;
   */
}

.radio label::before {
  content: "";
  display: inline-block;
  position: absolute;
  width: 17px;
  height: 17px;
  left: 0;
  margin-left: -20px;
  border: 1px solid #cccccc;
  border-radius: 50%;
  background-color: transparent;
  -webkit-transition: border 0.15s ease-in-out;
  -o-transition: border 0.15s ease-in-out;
  transition: border 0.15s ease-in-out;
}

.radio label::after {
  display: inline-block;
  position: absolute;
  content: " ";
  width: 11px;
  height: 11px;
  left: 3px;
  top: 3px;
  margin-left: -20px;
  border-radius: 50%;
  background-color: #555555;
  -webkit-transform: scale(0, 0);
  -ms-transform: scale(0, 0);
  -o-transform: scale(0, 0);
  transform: scale(0, 0);
  -webkit-transition: -webkit-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33);
  -moz-transition: -moz-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33);
  -o-transition: -o-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33);
  transition: transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33);
}

.radio input[type="radio"] {
  opacity: 0;
  z-index: 1;
}

.radio input[type="radio"]:checked+label::after {
  -webkit-transform: scale(1, 1);
  -ms-transform: scale(1, 1);
  -o-transform: scale(1, 1);
  transform: scale(1, 1);
}

/* ~Change to primary yellow */

.radio-warning input[type="radio"]+label::after {
  background-color: #f0ad4e;
}

.radio.radio-sm label::before {
  width: 30px;
  height: 30px;
  top: -13px;
}

.radio.radio-sm label::after {
  width: 22px;
  height: 22px;
  padding-left: 4px;
  font-size: 20px;
  left: 4px;
  top: -9px;
}

.radio.radio-sm label {
  padding-left: 18px;
  top: 13px;
}

.radio.radio-md label::before {
  width: 34px;
  height: 34px;
  top: -17px;
}

.radio.radio-md label::after {
  width: 26px;
  height: 26px;
  padding-left: 4px;
  font-size: 24px;
  left: 4px;
  top: -13px;
}

.radio.radio-md label {
  padding-left: 22px;
  top: 17px;
}

.radio.radio-lg label::before {
  width: 46px;
  height: 46px;
  top: -28px;
}

.radio.radio-lg label::after {
  width: 36px;
  height: 36px;
  padding-left: 4px;
  font-size: 36px;
  left: 5px;
  top: -23px;
}

.radio.radio-lg label {
  padding-left: 34px;
  top: 32px;
}

.radio-warning input[type="radio"]:checked+label::before {
  outline: none !important;
}

.radio-warning input[type="radio"]:checked+label::after {
  outline: none !important;
}
<div class="radiobuttons">

  <div class="d-inline">
    <div class="radio radio-warning radio-sm">
      <input type="radio" name="radio" id="my_radio_button_id1" />
      <label for="my_radio_button_id1">Add hoc</label>
    </div>
  </div>

  <div class="d-inline">
    <div class="radio radio-warning radio-sm">
      <input type="radio" name="radio" id="my_radio_button_id2" />
      <label for="my_radio_button_id2">Per day</label>
    </div>
  </div>

  <div class="d-inline">
    <div class="radio radio-warning radio-sm">
      <input type="radio" name="radio" id="my_radio_button_id3" />
      <label for="my_radio_button_id3">Per month</label>
    </div>
  </div>
  <div class="d-inline">
    <div class="radio radio-warning radio-sm">
      <input type="radio" name="radio" id="my_radio_button_id4" />
      <label for="my_radio_button_id4">Contract duration</label>
    </div>
  </div>
</div>

这个JS小提琴是我想要的布局,以便单选按钮和标签位于div的中心:

https://jsfiddle.net/Rick1107/u8p732zm/55/

.checkboxgroup {
  display: inline-block;
  text-align: center;
  padding: 0.5rem;
}

.checkboxgroup label {
  display: block;
  margin-top: 1rem;
}

input[type=radio] {
  transform: scale(2);
}
<div class="checkboxes">

  <div class="checkboxgroup radio-warning">
    <input type="radio" name="radio" id="my_radio_button_id1" />
    <label for="my_radio_button_id1">Add hoc</label>
  </div>
  
  <div class="checkboxgroup radio-warning">
    <input type="radio" name="radio" id="my_radio_button_id2" />
    <label for="my_radio_button_id2">Per day</label>
  </div>
  
  <div class="checkboxgroup radio-warning">
    <input type="radio" name="radio" id="my_radio_button_id3" />
    <label for="my_radio_button_id3">Per month</label>
  </div>
  
  <div class="checkboxgroup radio-warning">
    <input type="radio" name="radio" id="my_radio_button_id4" />
    <label for="my_radio_button_id4">Contract duration</label>
  </div>
</div>

以下是我要实现的目标的图像:

enter image description here

任何帮助将不胜感激,因为这使我发疯。

谢谢。

0 个答案:

没有答案