我有asp.net网站.由于某种原因,我不能在我的代码中使用javascript.我使用此代码创建一个可扩展的表:
html,body,form {
margin: 0 auto;
padding: 0;
text-align: left;
height: 100%;
top: 0;
bottom: 0;
overflow: hidden;
}
tr:nth-child(even) {
background: #F5F5F5;
}
tr:nth-child(odd) {
background: #DCDCDC;
}
tr:hover
{
background-color: #D3D3D3;
}
.toggle-Box {
display: none;
}
.toggle-Box + label {
cursor: pointer;
display: block;
font-weight: bold;
line-height: 25px;
margin-bottom: 2px;
margin-left: 5px;
background-color: #F1F8FF;
border-bottom: 1px solid gray;
}
.toggle-Box + label:hover {
background-color: #C5ECFF;
}
.toggle-Box + label + div {
display: none;
margin-bottom: 10px;
margin-left: 20px;
}
.toggle-Box:checked + label + div {
display: block;
}
.toggle-Box + label:before {
background-color: #66AEFF;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
color: #FFFFFF;
content: "+";
display: block;
float: left;
font-weight: bold;
height: 25px;
line-height: 25px;
margin-right: 5px;
text-align: center;
width: 25px;
}
.toggle-Box:checked + label:before {
content: "\2212";
}
#matru {
border: 0;
text-align: left;
position: absolute;
top: 100px;
left: 300px;
}
最佳答案
诀窍很简单.只需将复选框中的输入替换为radio,并在所有输入中添加具有相同值的属性名称.
这种变化意味着只有一个输入可以同时检查.因此,如果您点击一个项目,其他所有项目都将被关闭.
html,form {
margin: 0 auto;
padding: 0;
text-align: left;
height: 100%;
top: 0;
bottom: 0;
overflow: hidden;
}
tr:nth-child(even) {
background: #F5F5F5;
}
tr:nth-child(odd) {
background: #DCDCDC;
}
tr:hover
{
background-color: #D3D3D3;
}
.toggle-Box {
display: none;
}
[type="reset"] {
border: 0;
width: 100%;
text-align: inherit;
padding: 0;
font: inherit;
margin: 0;
outline:0 !important;
}
.toggle-Box + label,[type="reset"]{
cursor: pointer;
display: block;
font-weight: bold;
line-height: 25px;
margin-bottom: 2px;
margin-left: 5px;
background-color: #F1F8FF;
border-bottom: 1px solid gray;
}
.toggle-Box + label:hover {
background-color: #C5ECFF;
}
.toggle-Box + label + button {
display:none;
}
.toggle-Box:checked + label {
display:none;
}
.toggle-Box:checked + label + button {
display:block;
}
.toggle-Box + label + button + div {
display: none;
margin-bottom: 10px;
margin-left: 20px;
}
.toggle-Box:checked + label + button + div {
display: block;
}
.toggle-Box + label:before,[type="reset"]:before{
background-color: #66AEFF;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
color: #FFFFFF;
content: "+";
display: block;
float: left;
font-weight: bold;
height: 25px;
line-height: 25px;
margin-right: 5px;
text-align: center;
width: 25px;
}
.toggle-Box:checked + label:before {
content: "\2212";
}
#matru {
border: 0;
text-align: left;
position: absolute;
top: 100px;
left: 300px;
}