【问题标题】:CSS checkbox:checked not workingCSS复选框:选中不工作
【发布时间】:2014-07-19 09:12:37
【问题描述】:

我正在尝试使用复选框来更改表格中某些文本的颜色,但它似乎不起作用。 :checked 属性似乎不起作用。文字在 .代码如下:

<html>
<head>
<style type="text/css">
.methodoption
{

}
#row1
{
    color: blue;
}
#buyer1 + #row1
{
    color: blue;
}

#buyer1 input[type=checkbox]:checked ~ #row1
{
    color: red;
}

</style>
</head>
<body>
<div align="justify" style="font-size: 23px;"> 
                                Social compliance has changed a lot over the past few years. Several high-profile industry disasters in key sourcing countries like Bangladesh, along with heightened awareness among consumers about where their clothes come from, has prompted stakeholders all across the supply chain, from production facilities to brands and buyers, to rethink their approach to compliance and supply chain security. As part of our commitment to being a responsive and effective social compliance monitoring partner, we at WRAP wanted to get an idea of what some of these changes were and how we can adapt our own program to better meet those needs.</div><br/>
<div align="Center" style="Font-size: 29px;">WE TALKED TO <STRONG>50</STRONG> BUYERS, THOUGHT LEADERS,<br/>AND OTHER STAKEHOLDERS IN THE SOCIAL COMPLIANCE ARENA</div>
<div align="Center"><img src="infogfx.png" height="350" width="900"></div><br/><br/>
<table align="center" width="600" style="background-color: #aaaaaa;"><tr><td align="center"><em><strong style="font-size: 25px;">WHO ARE THEY?</strong></em></td></td>
<tr><td>In exchange for their participation in they survey, we have agreed to keep the identities of those who particiapted anonymous.</td></tr><table>

<form action="" method="post">
<table>
<tr><td><input type="checkbox" name="buyer1" id="buyer1"></td><td>1</td><td class="methodoption"><span id="row1">Stakeholder Expectations</span></td></tr>
<tr><td><input type="checkbox" name="buyer2a" id="buyer2a"></td><td>2(tie)</td><td class="methodoption">Factory Compliance/Strengthen Supply Chain</td></tr>
<tr><td><input type="checkbox" name="buyer2b" id="buyer2b"></td><td>2(tie)</td><td class="methodoption">Corporate Philosophy</td></tr>
<tr><td><input type="checkbox" name="buyer4" id="buyer4"></td><td>4</td><td class="methodoption">Integrity of Brand</td></tr>
<tr><td><input type="checkbox" name="buyer5a" id="buyer5a"></td><td>5(tie)</td><td class="methodoption">Risk Management</td></tr>
<tr><td><input type="checkbox" name="buyer5b" id="buyer5b"></td><td>5(tie)</td><td class="methodoption">Right Thing To Do</td></tr>
</table></form>

</body>
</html>

【问题讨论】:

  • @Daniel Lisik:这听起来非常像 W3Schools 的引述……如果是这样,那么该页面可能已经 10 年没有更新了。现在每个浏览器都支持它。

标签: html css checkbox css-selectors checked


【解决方案1】:

General Sibling Selector ~,顾名思义,选择兄弟姐妹。兄弟姐妹是在同一个父节点中找到的元素。您的 input 元素与您的 #row1 元素不在同一 td 下,因此不可选择。

为此,您需要将#row1 元素包含在与input 元素相同的td 中:

<td>
    <input type="checkbox" ... />
    <span id="row1"> ... </span>
</td>

【讨论】:

  • 那么我应该放什么,我已经尝试了“+”,只是一个空格
  • 您无法使用 CSS 实现您想要实现的目标。 + 也选择一个兄弟。见w3.org/TR/selectors/#selectors
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-09
  • 2019-05-02
  • 1970-01-01
  • 2014-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多