css - 单选按钮 CSS

标签 css

我想弄清楚如何使用 css 以相同的方式替换我所有的单选按钮。是否可以使用 css 使这些单选按钮无论输入位置在哪里都可以工作?我不想调整行或任何东西。只需捕获单选按钮并按照我在下面的示例中使用的方式对其进行 CSS。

body {
  background-color: white;
  margin: 0;
  padding: 0;
}
input[type='radio'] {
  display: none;
}
.radio {
  border: 1px solid #b3b4b4;
  border-radius: 50%;
  box-sizing: border-box;
  cursor: pointer;
  display: block;
  float: left;
  height: 16px;
  margin: 10px 10px 0 0;
  padding: 10px;
  position: relative;
  width: 16px;
}
.row:hover .radio {
  border: 2px solid #218996;
}
input[type='radio']:checked + .radio {
  background-color: #218996;
  border: 2px solid #218996;
}
input[type='radio']:checked + .radio::before {
  content: "✓ ";
  position: absolute;
  color: white;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size:
}
.row {
  border-bottom: 1px solid #dcdcdc;
  padding: 0 5px;
}
.row label {
  display: inline-block;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: bold;
}
.row > label:last-child {
  padding: 12px 0;
  width: calc(100% - 50px);
  cursor: pointer;
}
<form name="titleTypes" id="titleTypes" method="post" action="process.cfm">
  <div>
    <!---Label is here for placement of error message--->
    <label for="rgroup" class="error" style="display:none;">Please choose one.</label>
  </div>

  <div class='row'>
    <input id="one" type="radio" name="rgroup" value="MV/titleTypeMV.cfm" />
    <label for="one" class='radio' tabindex='1'></label>
    <label for="one">MOTOR VEHICLE / TRAVEL TRAILER TITLE</label>
  </div>

  <div class='row'>
    <input id="two" type="radio" name="rgroup" value="MH/mobileHome.cfm" />
    <label for="two" class='radio' tabindex='1'></label>
    <label for="two">MOBILE HOME</label>
  </div>

  <div class='row'>
    <input id="three" type="radio" name="rgroup" value="BOAT/boat.cfm" />
    <label for="three" class='radio' tabindex='1'></label>
    <label for="three">VESSEL</label>
  </div>

  <div class='row'>
    <input id="four" type="radio" name="rgroup" value="DUPL/duplicate.cfm" />
    <label for="four" class='radio' tabindex='1'></label>
    <label for="four">DUPLICATE</label>
  </div>

  <div>
    <button class="btn-u" type="submit" name="submit" id="submitBtn" class="submitBtn"><i></i>Next</button>
  </div>

我希望输入单选按钮能够像这些单选按钮一样工作,无论是在 table 上还是在任何地方,只需调用类即可。这可能吗?

最佳答案

根据我们在评论中的对话,我稍微修改了您的 CSS 以在它们设计的行之外工作。主要是,我添加了一个 clear: both;.radio 以将每个输入放在一个新行上,并添加了 float: left; 到 both标签,以便它们保持一致。

input[type='radio'] {
  clear: both;
  float: left;
  width: 20px;
  height: 10px;
  opacity: 0;
}
.radio {
  border: 1px solid #b3b4b4;
  border-radius: 50%;
  box-sizing: border-box;
  cursor: pointer;
  display: block;
  height: 16px;
  margin: 0 10px 10px -20px;
  padding: 10px;
  position: relative;
  width: 16px;
}
input[type='radio']:checked + .radio {
  background-color: #218996;
  border-color: #218996;
}
input[type='radio']:active + .radio,
input[type='radio']:focus + .radio {
  border-color: lightblue;
}
input[type='radio']:checked + .radio::before {
  content: "✓ ";
  position: absolute;
  color: white;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
label {
  float: left;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: bold;
  line-height: 20px;
}
<input id="one" type="radio" name="rgroup" tabindex='1' />
<label for="one" class='radio'></label>
<label for="one">Button 1</label>

<input id="two" type="radio" name="rgroup" tabindex='2' />
<label for="two" class='radio'></label>
<label for="two">Button 2</label>

关于css - 单选按钮 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41231053/

相关文章:

javascript - 如何修复奇怪的 <div> 覆盖行为?

javascript - jQuery slideUp 然后在鼠标悬停时 slideDown

css - Angular:如何更改 <mat-nav-list> 中的图标?

jquery - 滚动到固定高度表中的事件表行

javascript - 我的网站模板是否包含内置搜索功能?

jquery - 在 Bootstrap 选项卡 View 中更改选项卡样式

css - 将鼠标悬停在内部 <a> 元素上时更改外部 DIV 的属性

html - 如何删除按钮样式或覆盖动态添加的类到 material2 中的按钮

javascript - 如何将 Bootstrap 导航菜单设置为在滚动时保持在页面顶部

html - 使用居中文本在 html 中创建椭圆