我正試圖在桌面上隱藏div。我嘗試過媒體查詢(這裏Caroline的解決方案是一個例子:https://ecommerce.shopify.com/c/ecommerce-design/t/display-content-on-mobile-or-desktop-only-211885)在桌面上隱藏div
我已經得到了我的大導航(.menu)隱藏在手機上,但我無法弄清楚如何隱藏我的mobilenav桌面。如果我在主CSS中將mobilenav的顯示設置爲「隱藏」,並在我的媒體查詢中顯示爲「阻止」,則div保持隱藏狀態。我猜測我的代碼在某處存在問題。你有任何建議,將不勝感激。這裏是我的小提琴:
https://jsfiddle.net/eamr662L/(對網站的完整的代碼)
這裏是我想什麼是相關代碼的摘錄:
mobilenav {
display: block;
width: 100%;
z-index: 1000;
background-color: #000000;
text-align: center;
}
mobilenav div {
width: 100%;
}
mobilenav a {
color: #ffffff;
text-transform: uppercase;
}
mobilenav a:hover {
color: #ffffff;
text-decoration: underline;
}
mobilenav > nav > ul {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
list-style: none;
margin: 0;
padding: 0;
}
mobilenav > nav > ul:hover {
background-color: #000000;
}
mobilenav > nav > ul > li {
flex: 0 1 auto;
margin: 0;
padding: 0;
position: relative;
width: 100%;
transition: all linear 0.1s;
}
mobilenav > nav > ul > li a + div {
display: none;
position: absolute;
}
mobilenav > nav > ul > li:hover a + div {
display: block;
background-color: #000000;
}
mobilenav > nav > ul > li a + div > ul {
list-style-type: none;
}
mobilenav > nav > ul > li a + div > ul > li {
margin: 0;
padding: 0;
}
mobilenav > nav > ul > li a + div > ul > li > a {
display: block;
padding: .25rem 1.5rem;
text-decoration: none;
}
mobilenav > nav > ul > li > a {
align-items: flex-start;
display: flex;
padding: 1rem 1.5rem;
text-decoration: none;
}
<mobilenav>
<nav role="navigation">
<ul>
<li>
<a href="">
<div>Navigation</div>
</a>
<div>
<ul>
<li><a href="">Home</a></li>
<li><a href="">About Us</a></li>
<li ><a href="">Research</a></li>
<li><a href="">Services</a></li>
<li><a href="">Ask a Librarian</a></li>
<li><a href="">Archives & Special Collections</a></li>
<li><a href="">Exhibitions</a></li>
<li><a href="">Plant Information</a></li>
</ul>
</div>
</li>
</ul>
</nav>
</mobilenav>
這裏的網站:
http://nybg.beta.libguides.com/
謝謝!
你應該表現出 – doz87