0
A
回答
-2
例如根據您的需求量的嘗試這些....和修改。
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Dropdown</a>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</li>
</ul>
<h3>Dropdown Menu inside a Navigation Bar</h3>
</body>
</html>
+0
謝謝,但不幸的是我需要一個解決方案,不使用引導帶 – Charlie
+0
現在嘗試上面的代碼 –
0
所以,就需要有一些JavaScript。這是我從w3schools收到的一個工作示例。你可以在這裏閱讀完整的文章:https://www.w3schools.com/howto/howto_js_topnav_responsive.asp
基本上你所做的是,你使用媒體查詢在手機視圖中隱藏菜單,改變它的風格,然後使用javascript顯示它們。
你需要JavaScript的菜單下拉切換工作。其餘由CSS處理。
如果您有任何疑問,可以將它們置於評論中。
/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<div class="topnav" id="myTopnav">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">☰</a>
</div>
0
第一隱藏使用@media和改變的元素到列表視圖
@media screen and (max-width: 850px){
//replace max width with your width
ul li {
display: block;
}
ul {
display: none;
}
}
Showmenu功能的導航欄元件切換導航欄的元素的可見性
function showmenu()
{
var x = document.getElementById('myUL');
if (x.style.display == 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
還添加一個按鈕來觸發功能
<!DOCTYPE html>
<html lang="en">
<head>
<button onclick = 'showmenu();'>click me to see menu</button>
<ul id='myUL'>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</head>
</html>
希望這有助於
相關問題
- 1. 導航欄沒有崩潰
- 2. Bootstrap導航欄不崩潰
- 3. 防止導航欄崩潰
- 4. HTML,JS:滾動到不可靠與崩潰導航欄
- 5. iphone - 導航欄應用程序崩潰
- 6. Bootstrap響應式導航欄不崩潰
- 7. 更改boostrap導航欄崩潰斷點
- 8. Bootstrap 3 - 點擊導航欄後崩潰
- 9. Twitter Bootstrap 3導航欄崩潰錯誤
- 10. Bootstrap崩潰導航欄不擴展
- 11. 按鈕後退導航欄崩潰
- 12. 下拉當導航欄崩潰
- 13. Bootstrap導航欄不崩潰(防止)
- 14. 導航欄崩潰不起作用
- 15. 導航欄崩潰不起作用
- 16. 頁面加載與導航欄擴展 - 已經檢查「崩潰」
- 17. Bootstrap 3.2導航欄不能與jquery.min.map崩潰
- 18. Bootstrap導航欄崩潰問題與多個標頭
- 19. 導航菜單不崩潰
- 20. 引導程序崩潰移動導航欄不起作用
- 21. 修復體時引導導航欄崩潰
- 22. 引導禁用崩潰/切換導航欄上
- 23. 引導導航欄不正確時崩潰
- 24. 引導崩潰導航欄不垮在平板電腦上
- 25. 在導航欄不工作的引導程序崩潰
- 26. 我如何讓我的Bootstrap導航欄「崩潰」?
- 27. 應用程序崩潰處理導航欄按鈕事件
- 28. 讓Twitter Bootstrap導航欄在崩潰時返回頁首
- 29. Bootstrap導航欄不會在手機上崩潰
- 30. bootstrap導航欄崩潰圖標不觸發在codepen
嗨查理。這不是一個完整的問題。關於您嘗試或實施的內容沒有足夠的細節。我會請你做一個基礎研究,並嘗試首先實現某些東西。當你無法實施任何事情時,請向我們詳細介紹你所面臨的問題。這將使我們能夠更好地幫助你。請參閱[如何提問](https://stackoverflow.com/help/how-to-ask)頁面以獲得澄清此問題的幫助。 – viCky
我已經嘗試過了,我可以找到的每個示例都使用bootstrap,顯然是因爲它更簡單,但由於我的情況,我無法使用bootstrap。 有一個這樣的線程,如何在沒有引導的情況下執行此任務的答案對於我的情況中的很多人非常有用 – Charlie