css - 选择按钮时选择单选按钮列表的容器

标签 css html css-selectors

我有几个带有单选按钮的容器。我希望选定一个包含选定单选按钮的容器:

input[type="radio"]:checked+.container {
  border: 5px solid red;
}
<div class="container">
  <input class="btn-radio" type="radio" value="123" name="rd" />
</div>


<div class="container">
  <input class="btn-radio" type="radio" value="1234" name="rd" />
</div>


<div class="container">
  <input class="btn-radio" type="radio" value="12345" name="rd" />
</div>

为什么不起作用?

最佳答案

这是我上面评论的工作代码

input[type="radio"]:checked + .border {
    border: 5px solid red;
}

.container {
    position: relative;
    max-width: 100px;
    margin: 10px;
}

input {
    position: relative;
    z-index: 100;
}

.border {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
}
<div class="container">
    <input class="btn-radio" type="radio" value="123" name="rd" />Input 1
    <div class="border"></div>
</div>
<div class="container">
    <input class="btn-radio" type="radio" value="1234" name="rd" />Input 2
    <div class="border"></div>
</div>
<div class="container">
   <input class="btn-radio" type="radio" value="12345" name="rd" /> Input 3
     <div class="border"></div>
</div>

关于css - 选择按钮时选择单选按钮列表的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50784047/

相关文章:

CSS 选择器 :focus not working with Chromecast

javascript - jquery scrollto 不滚动

css - 反作用力背景色全高

html - libxml2 HTML解析

css - 更改单个顶部栏元素及其下拉菜单的背景

html - 使用 CSS 定位一组元素类型中的最后一个元素

html - 网站更新延迟(保存时不更新)

html - 使用 :before and :after elements to fill remaining space of text element

asp.net - 为什么我的 cookie 设置没有被应用?

html - CSS :not() with [attribute*=value] selector not works properly