我花了整個上午都在試圖寫了我認爲是一個簡單的代碼位的邏輯。困惑過DIV Z-指數,加上可見/隱藏層
- 兩個長的內容列,只有第1欄是可見的
- 上的鏈接的點擊,第1列是隱藏的,第2列變得可見
- 兩者都是完全相同的位置,但都有不同和不同的長度
我決定使用target
僞類在列之間切換,設置要顯示的可見性。
這似乎工作,但我不完全明白我所做的。此外,這些列下方的內容似乎放置在z軸下方,而不是在y軸下方。
我的兩個(相關)的問題:
- 我不完全知道什麼是邏輯的,我創造了什麼,我可以用一個簡單的英語解釋這樣做。
- 我不明白爲什麼在兩列和容器下面的DIV沒有出現在y軸下面。
這裏是我的CSS:
#container
{
background-color: red;
position: relative;
}
#schools-list
{
width: 400px; /* Set the width of the visible portion of content here */
height: 600px; /* Delete the height, let the content define the height */
background-color: purple;
position: absolute;
top: 0;
left: 0;
}
#boards-list
{
width: 400px; /* Set the width of the visible portion of content here */
height: 700px; /* Delete the height, let the content define the height */
background-color: green;
position: absolute;
top: 0;
left: 0;
visibility: hidden;
}
#container:target #schools-list
{
visibility: hidden;
}
#container:target #boards-list
{
visibility: visible;
}
這裏是我的HTML:
<div id="container">
<div id="boards-list">
Boards List<br>
Switch to <a href="">Schools List</a>
Here's some content
</div>
<div id="schools-list">
Schools List<br>
Switch to <a href="#container">Boards List</a>
Here's some other content
</div>
</div>
<div>Why is this beneath everything?</div>
嘗試在兩個列表容器中添加'clear:both;'。 –