我想制作一個在單擊時展開并在再次單擊時關閉的視窗。我正在使用燒瓶來顯示所有資料行,但這應該不是問題,實際上可以忽略。現在我已經設定了,當你點擊 div 時它會展開,但是一旦你放手,div 就會再次關閉。有什么辦法可以把這個 div 變成某種使用 python 或 javascript 甚至 CSS 的開關?
HTML/Python 燒瓶:
<div class="container">
{%for i, value in verb_data.items() %}
<div class="indevidual_verbs">{{ i }} . {{ value }}</div><br>
{%endfor%}
</div>
CSS:
.indevidual_verbs {
cursor: pointer;
}
.indevidual_verbs:active {
padding-bottom: 300px;
}
uj5u.com熱心網友回復:
根據您想要做什么,您甚至可以使用details html 元素,它會自動實作該功能。
如果您可以使用 javascript,則有一種方法可以輕松切換類:
// Get a reference to the container
const container = document.getElementById("container");
// When we click on the container...
container.addEventListener("click", function (e) {
// we can toggle the "open" class
this.classList.toggle("open");
});
/* Just a way to show the container */
#container {
padding: 20px;
border: solid 1px #000;
}
/* Hide the content (you can do it in many different ways) */
#container .inner {
display: none;
}
/* Show the content when the "open" class is added to the container */
#container.open .inner {
display: block;
}
<div id="container">
<div class="inner">
This is just some example text
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/462548.html
標籤:javascript html css
