css导航栏_使用CSS的导航栏
css導航欄
CSS | 導航欄 (CSS | Navigation Bar)
Developing websites is great but developing a user-friendly website is even greater. So how does one design a user-friendly website? What tools to use? Well, there are many tools to mention which are quite helpful in making a website user-friendly. So let's discuss one such tool which is Navigation Bar.
開發網站很棒,但是開發用戶友好的網站則更大。 那么,如何設計一個用戶友好的網站呢? 使用什么工具? 好了,有很多工具值得一提,它們對使網站易于使用非常有幫助。 因此,讓我們討論一種這樣的工具,即Navigation Bar 。
Navigation Bar, what is the first thought that comes into mind after listening to this term. Quite simply though, a menu option for navigating throughout that particular page or site. The navigation bar also lets people move from one page to another. The navigation bar works as a guide for the user to surf through the pages.
導航欄 ,聽完該術語后想到的第一個想法是什么。 雖然很簡單,但是菜單選項用于瀏覽特定頁面或站點。 導航欄還允許人們從一頁移動到另一頁。 導航欄可作為用戶瀏覽頁面的指南。
The navigation bar is created with the help of menu items taken together. Like an ordered list or unordered list, these list items can be arranged into various positions like horizontally, vertically, right-aligned, etc. Therefore one should be clear in mind about the type of navigation bar he/she wants to use on the webpage.
導航欄是在菜單項結合在一起的情況下創建的。 就像有序列表或無序列表一樣,這些列表項可以按水平,垂直,右對齊等各種位置排列。因此,應該牢記他/她想在網頁上使用的導航欄的類型。
Besides being aware of the navigation bar, one should also make sure that the links provided in the navigation bar are correct otherwise the user may access the wrong page without even being aware and that creates problems.
除了知道導航欄外 ,還應確保導航欄中提供的鏈接正確無誤,否則用戶可能會訪問錯誤的頁面而根本不知道并造成問題。
let's talk about some type of navigation bars in detail,
讓我們詳細討論一些類型的導航欄,
Vertical navigation bar
垂直導航欄
Horizontal navigation bar
水平導航欄
Fixed navigation bar
固定的導航欄
1)垂直導航欄 (1) Vertical Navigation Bar)
The vertical navigation bar is used to display the menu options vertically. You can use the display property and set it to block. By using display property and setting it to block means that the entire block consisting of your menu item will become clickable. You can also set the width of these blocks as well.
垂直導航欄用于垂直顯示菜單選項。 您可以使用display屬性并將其設置為block。 通過使用display屬性并將其設置為block意味著包含菜單項的整個塊將變為可單擊。 您也可以設置這些塊的寬度。
CSS Syntax:
CSS語法:
Element{display: block;width: 50px;}Example:
例:
<!DOCTYPE html> <html><head><style>li a {display: block;width: 90px;background-color: #dddddd;}</style> </head><body><ul><li><a href="#student">student</a></li><li><a href="#staff">staff</a></li><li><a href="#dean">dean</a></li></ul> </body></html>Output
輸出量
In the above example, displaying the links as block elements makes the whole link area clickable.
在上面的示例中,將鏈接顯示為塊元素使整個鏈接區域可單擊。
2)水平導航欄 (2) Horizontal Navigation Bar)
In a horizontal navigation bar as the name suggests the elements can be arranged horizontally. Now, this can be done in two ways, first, using inline property and second is by using the floating property.
顧名思義,在水平導航欄中可以將元素水平放置。 現在,這可以通過兩種方式完成,一種是使用內聯屬性,第二種是使用float屬性。
1) inline
1)內聯
In "inline property" the elements are by default block items, the line break is removed from before and after of each list item so that they can be shown in one line.
默認情況下,在“內聯屬性”中 ,元素是塊項,從每個列表項的前后刪除換行符,以便可以將它們顯示在一行中。
Syntax for inline:
內聯的語法:
Element{display: inline;}Example:
例:
<!DOCTYPE html> <html><head><style>li {display: inline;}</style> </head><body><ul><li><a href="#student">student</a></li><li><a href="#staff">staff</a></li><li><a href="#dean">dean</a></li></ul> </body></html>Output
輸出量
In the above example, the elements are displayed in a single line.
在上面的示例中,元素顯示在一行中。
2) floating:
2)浮動:
"floating property" is used to adjust elements next to each other.
“浮動屬性”用于調整彼此相鄰的元素。
Syntax for floating:
浮動語法:
element{float: left; }Example:
例:
<!DOCTYPE html> <html><head><style>li {display: block;float: left;}</style> </head><body><ul><li><a href="#student">student</a></li><li><a href="#staff">staff</a></li><li><a href="#dean">dean</a></li></ul> </body></html>Output
輸出量
In the above example, the elements are displayed next to each other without any space.
在上面的示例中,元素彼此相鄰顯示,沒有任何空格。
3)固定位置導航欄 (3) Fixed position navigation bar)
These types of navigation bar stay fixed to their positions be it top or bottom even when the user scrolls down or up the page.
即使用戶向下或向上滾動頁面,這些類型的導航欄也將固定在頂部或底部。
CSS Syntax:
CSS語法:
Element{// for fixed topposition: fixed; // To fix the bar at the toptop: 0;// for fixed bottom// To fix the bar at the bottombottom: 0;}Example:
例:
<!DOCTYPE html> <html><head><meta name="viewport" content="width=device-width, initial-scale=1"><style>.topnav {overflow: hidden;background-color: #333;}.topnav a {float: left;color: #f2f2f2;text-align: center;padding: 14px 16px;text-decoration: none;font-size: 17px;}.topnav a:hover {background-color: #ddd;color: black;}</style> </head><body><div class="topnav"><a class="active" href="#student">student</a><a href="#staff">staff</a><a href="#dean">dean</a></div><div style="padding-left:16px"><p>Some content..</p></div> </body></html>Output
輸出量
In the above example, the navigation stays at top even when we scroll the page.
在上面的示例中,即使我們滾動頁面,導航也位于頂部。
翻譯自: https://www.includehelp.com/code-snippets/navigation-bar-using-css.aspx
css導航欄
總結
以上是生活随笔為你收集整理的css导航栏_使用CSS的导航栏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据科学中的简单线性回归
- 下一篇: css clearfix_如何使用CSS