【发布时间】:2018-05-16 15:27:25
【问题描述】:
我正在为足球名单制作网页。我正在折叠/展开,所以当您单击播放器图片时,它将展开信息/统计信息。当我点击播放器时,它会展开所有播放器,我只想让它只展开你点击的一个播放器。如果有人可以帮助我找出 CSS 代码,那么当您单击单个播放器时,它将扩展他们的信息而不是所有播放器。
这是我的代码:
body {
font-family: "Open Sans", Arial;
}
main {
background: #EEE;
width: 300px;
margin: 20px auto;
padding: 10px 0;
}
h2 {
text-align: center;
}
h3 {
text-align: center;
}
p {
text-align: center;
font-size: 13px;
}
input {
display: none;
visibility: collapse;
}
label {
display: block;
padding: 0.5em;
text-align: center;
}
label:hover {
cursor: grabbing;
color: #000;
}
.expand {
height: 0px;
overflow: hidden;
color: #FFF;
}
section {
padding: 0 20px;
}
#toggle:checked~.expand {
height: 300px;
}
#toggle:checked~label::before {
content: "-";
}
#toggle2:checked~.expand {
height: 300px;
}
#toggle2:checked~label::before {
content: "-";
}
<input id="toggle" type="checkbox">
<label for="toggle"><img src="https://media-public.fcbarcelona.com/20157/0/document_thumbnail/20197/148/55/202/46806932/1.0-1/46806932.jpg?t=1495555185000" width="200" height="250" alt=""/></label>
<div class="expand">
<section>
<h3>Lionel Messi</h3>
<p></p>
</section>
</div>
<input id="toggle2" type="checkbox">
<label for="toggle2"><img src="https://upload.wikimedia.org/wikipedia/commons/3/39/DK-Beshiktash_%281%29.jpg" width="200" height="250" alt=""/></label>
<div class="expand">
<section>
<h3>Other content</h3>
<p></p>
</section>
</div>
【问题讨论】:
-
你看过 HTML
<details>标签了吗? w3schools.com/tags/tag_summary.asp或许可以满足你的需求 -
请看我编辑的答案,我修复了你的代码。如果您仍有疑问,请随时提出。如果我解决了你的问题,你应该检查我的回答,将此问题标记为“已解决”
-
"Can someone help me?" is not an actual question 您需要编写自己的代码并向我们展示您的尝试。我们可以为您提供帮助,但 SO 不是代码编写服务。