我需要一個笑話網站的代碼,我試圖做,它使用顯示/隱藏按鈕來顯示內容/隱藏內容。多個CSS只顯示/隱藏按鈕(沒有Java/jQuery)
它開始隱藏,然後有一個按鈕來改變它。
但是,它不能包含任何JavaScript或jQuery的,因爲這是學校項目的assesment我這樣做(這是對CSS爲主)
是有可能有多個?到目前爲止,我只取得了一個。
到目前爲止我的代碼(我得到它關閉這個網站http://cssdeck.com/labs/css-only-showhide的):
<article>
<input type="checkbox" id="RMa" role="button">
<label for="RMa" onclick=""><span>Show</span><span>Hide</span></label>
<section>
<p>Joke</p>
</section>
<section>
<p>Punchline</p>
</section>
</article>
(CSS)
article {
position: relative;
}
article:before, :after {
display: table;
}
article:after { clear: both }
article section:last-of-type {
display: none;
visibility: hidden;
}
input[type=checkbox] {
width: 1px;
overflow: hidden;
position: absolute;
}
[for="read_more"] {
position: absolute;
left: 100px;
width: ;
text-align: center;
box-shadow: inset 1px 1px rgba(0, 0, 0, 0.1), inset -1px -1px rgba(0, 0, 0, 0.1);
}
[for="read_more"]:hover {
background: rgba(0,0,0,.5);
color: rgb(255,255,255);
}
[for="read_more"] span:last-of-type {
display: none;
visibility: hidden;
}
input[type=checkbox]:checked ~ section {
display: block;
visibility: visible;
width: 100%;
}
input[type=checkbox]:checked ~ figure { width: 100% }
input[type=checkbox]:checked ~ [for="read_more"] span:first-of-type {
display: none;
visibility: hidden;
}
input[type=checkbox]:checked ~ [for="read_more"] span:last-of-type {
display: block;
visibility: visible;
}
您鏈接的網站上的第二條評論說明其他人如何將其應用於多個條目。你試過了嗎? –
@ FuzzBall007不,我還沒有,謝謝你的意識到! – Squinty
幹得好!它是如何工作的? – M98