這通常是一個黑客,我試圖弄清楚在CSS中,從我可以收集它應該在理論上工作,而事實並非如此。僅限CSS多次onclick事件
#expand {
width: 30px;
height: 30px;
background-color: rgba(0, 0, 0, 0);
}
#btn {
display: none;
}
#btn:checked+label:before {
transform: rotate(90deg);
}
#btn:checked+label:after {
transform: rotate(180deg);
}
#btn:checked+.button:before {
display: none;
}
#btn:checked+.button:after {
display: inline-block;
}
.button {
position: relative;
width: 25px;
height: 25px;
display: inline-block;
}
.button:before,
.button:after {
content: "";
position: absolute;
background-color: black;
transition: transform 0.35s ease-out;
}
/* Vert Line */
.button:before {
top: 0;
left: 46%;
width: 4px;
height: 100%;
margin-left: 2px;
margin-top: 2px;
}
/* Horiz Line */
.button:after {
top: 50%;
left: 0;
width: 100%;
height: 4px;
margin-left: 2px;
}
.inform {
display: none;
}
<div id="expand">
<input id="btn" type="checkbox">
<label class="button" for="btn"></label>
<div class="inform">
<h3>Heading</h3>
<p>Alot of content.</p>
</div>
因此,大家可以看到,我有使用複選框改變風格.button
的「黑客」爲Click事件。 然後,我使用+
選擇器來定位div .inform
。 如果我是正確的+
選擇器意味着它的目標是緊接着的元素,在這種情況下,這應該工作。但事實並非如此,有人可能會幫助我清楚我對此的理解,如果我錯了,否則你能幫助指出我朝着正確的方向努力工作。
摘要: 我希望在複選框被選中時顯示標題和段落,以及讓+符號旋轉。
什麼不起作用?你的「+」變爲「 - 」點擊並返回。你想得到什麼? – DomeTune
我將重新編輯保留 – Ricky
已被低估並且沒有評論爲什麼? – Ricky