单选按钮出现在另一个上面

时间:2016-08-29 01:46:42

标签: html css styles radio

我的应用程序上有自定义单选按钮。我的问题是目前单选按钮单独显示。当我尝试将其中两个放在一条线上时......它们彼此出现而不是彼此相邻。我无法改变我的HTML,只能搞乱CSS。任何帮助将不胜感激。我认为这是由于每个标签的宽度,但给它一个低宽度有相同的结果。

HTML:

<label class="radio">
  <input type="radio">
  <span class="custom"><span>One</span></span>
</label>

CSS:

* {
  box-sizing: border-box;
}

input[type="radio"] {
  display: none;
  cursor: pointer;
}

label {
  cursor: pointer;
}

.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;
}

JSFiddle Demo

2 个答案:

答案 0 :(得分:1)

只需编辑标签类(仅举例):

label {
  cursor: pointer;
  display:inline-block;
  width: 50px;
  position:relative;
}

答案 1 :(得分:0)

如果你想单独定位每个人:

给每个span一个id标签并在你的css中使用它:

#your_span_id{ position: absolute; left:0px; height:100px; }
#your_second_span{ position:absolute; left:35px; height:100px;}

现在您的单选按钮位于彼此相邻的同一行中:)

欢呼声

scriptmind.js

相关问题