如何将文本放在单选按钮内?

时间:2017-07-22 20:56:19

标签: css radio-button materialize

我想在一个单选按钮(带有Materialize框架)中放一个字母,就像这个image中的A和B一样。

我该怎么做?

2 个答案:

答案 0 :(得分:2)

这是自定义单选按钮。

查看css。

中给出的评论



input[type="radio"] {
  width: 30px;
  height: 30px;
  border-radius: 15px;
  border: 2px solid #1FBED6;
  background-color: white;
  -webkit-appearance: none; /*to disable the default appearance of radio button*/
  -moz-appearance: none;
}

input[type="radio"]:focus { /*no need, if you don't disable default appearance*/
  outline-color: transparent; /*to remove the square border on focus*/
}

input[type="radio"]:checked { /*no need, if you don't disable default appearance*/
  background-color: #1FBED6;
}

input[type="radio"]:checked ~ span:first-of-type {
  color: white;
}

label span:first-of-type {
  position: relative;
  left: -27px;
  font-size: 15px;
  color: #1FBED6;
}

label span {
  position: relative;
  top: -10px;
}

<label>
  <input type="radio" name="options"/>
  <span>A</span><span>Option A</span>
</label>
<br/>
<label>
  <input type="radio" name="options"/>
  <span>B</span><span>Option B</span>
</label>
<br/>
<label>
  <input type="radio" name="options"/>
  <span>C</span><span>Option C</span>
</label>
<br/>
<label>
  <input type="radio" name="options"/>
  <span>D</span><span>Option D</span>
</label>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

你做不到。但相反,你可以使用CSS制作类似的东西:

&#13;
&#13;
label {display: block; padding: 5px; position: relative; padding-left: 20px;}
label input {display: none;}
label span {border: 1px solid #ccc; width: 15px; height: 15px; position: absolute; overflow: hidden; line-height: 1; text-align: center; border-radius: 100%; font-size: 10pt; left: 0; top: 50%; margin-top: -7.5px;}
input:checked + span {background: #ccf; border-color: #ccf;}
&#13;
<h3>Select One</h3>
<label><input type="radio" name="select" /><span>a</span> Item 1</label>
<label><input type="radio" name="select" /><span>b</span> Item 2</label>
&#13;
&#13;
&#13;

预览

preview