How to make navigation bar in html. CSS Navigation Bar
Horizontal menu is a list of sections of the site, so it is more logical to mark up inside the element
- and then apply CSS styles to its elements. This arrangement of the menu is the most common due to the obvious advantages in its positioning on a web page.
- Menu item
- Menu item
- Menu item ...
- Ease of use;
- Navigation should be created for all sections of the site;
- Each page of the site should have an exit to the main page;
- Go to any page of the site in a maximum of 3 clicks.
- Website menu creation a> - this is one of the positions where you will need to insert the necessary link into a href="#";
How to make a horizontal menu: markup and design examples
HTML markup and basic styles for the horizontal menu
By default, all list items are located vertically, spanning the entire width of the container element, which in turn spans the entire width of its container block.
HTML markup for horizontal navigation
A horizontal menu located inside the tag can additionally be placed inside the element and/or
There are several ways to place them horizontally. First you need to reset the default browser styles for navigation elements:
Ul ( list-style: none; /*remove the list markers*/ margin: 0; /*remove the top and bottom margins of 1em*/ padding-left: 0; /*remove the left padding of 40px*/ ) a ( text-decoration: none; /*remove the underlining of link text*/)
Method 1. li (display: inline;)
Make list items inline. As a result, they are arranged horizontally, on the right side, a gap equal to 0.4em is added between them (calculated relative to the font size). To remove it, add a negative right margin to li li (margin-right: -4px;) . Next, style the links as you wish.
Method 2. li (float: left;)
We make the elements of the list floating. As a result, they are arranged horizontally. The height of the ul container block becomes zero. To solve this problem, we add (overflow: hidden;) to ul , expanding it and allowing it to contain floating elements in this way. For links, add a (display: block;) and style them as you wish.
Method 3. li (display: inline-block;)
Making list items inline-block. They are arranged horizontally, a gap is formed on the right side, as in the first case. For links, add a (display: block;) and style them as you wish.
Method 4. ul (display: flex;)
Making the ul list a flexible container using the . As a result, the elements of the list are laid out horizontally. Add a (display: block;) for links and style them as you wish.
1. Responsive menu with underline effect when hovering over a link
@import url("https://fonts.googleapis.com/css?family=Ubuntu+Condensed"); .menu-main ( list-style: none; margin: 40px 0 5px; padding: 25px 0 5px; text-align: center; background: white; ) .menu-main li (display: inline-block;) .menu- main li:after ( content: "|"; color: #606060; display: inline-block; vertical-align:top; ) .menu-main li:last-child:after (content: none;) .menu-main a ( text-decoration: none; font-family: "Ubuntu Condensed", sans-serif; letter-spacing: 2px; position: relative; padding-bottom: 20px; margin: 0 34px 0 30px; font-size: 17px; text-transform: uppercase; display: inline-block; transition: color .2s; ) .menu-main a, .menu-main a:visited (color: #9d999d;) .menu-main a.current, .menu- main a:hover(color: #feb386;) .menu-main a:before, .menu-main a:after ( content: ""; position: absolute; height: 4px; top: auto; right: 50%; bottom : -5px; left: 50%; background: #feb386; transition: .8s; ) .menu-main a:hover:before, .menu-main .current:before (left: 0;) .menu-main a: hover:after, .menu-main .current:after (right: 0; ) @media (max-width: 550px) ( .menu-main (padding-top: 0;) .menu-main li (display: block;) .menu-main li:after (content: none;) .menu- main a ( padding: 25px 0 20px; margin: 030px; ) )2. Responsive menu for a wedding website
@import url("https://fonts.googleapis.com/css?family=PT+Sans"); .top-menu ( position: relative; background: #fff; box-shadow: inset 0 0 10px #ccc; ) .top-menu:before, .top-menu:after ( content: ""; display: block; height : 1px; border-top: 3px solid #575350; border-bottom: 1px solid #575350; margin-bottom: 2px; ).top-menu:after ( border-bottom: 3px solid #575350; border-top: 1px solid #575350; box-shadow: 0 2px 7px #ccc; margin-top: 2px; ) .menu-main ( list-style: none; padding: 0 30px; margin: 0; font-size: 18px; text-align: center; position: relative; ) .menu-main:before, .menu-main:after ( content: "\25C8"; line-height: 1; position: absolute; top: 50%; transform: translateY(-50% ); ) .menu-main:before (left: 15px;) .menu-main:after (right: 15px;) .menu-main li ( display: inline-block; padding: 5px 0; ) .menu-main a ( text-decoration: none; display: inline-block; margin: 2px 5px; padding: 6px 15px; font-family: "PT Sans", sans-serif; font-size: 16px; color: #777777; border-bottom : 1px solid transparent n: .3s linear; ) .menu-main .current, .menu-main a:hover ( border-radius: 3px; background: #f3ece1; color: #313131; text-shadow: 0 1px 0 #fff; border-color: #c6c6c6; ) @media (max-width: 500px) ( .menu-main li (display: block;) )3. Responsive menu with scallops
@import url("https://fonts.googleapis.com/css?family=PT+Sans+Caption"); .menu-main ( list-style: none; padding: 0 30px; margin: 0; font-size: 18px; text-align: center; position: relative; background: white; ) .menu-main:after ( content: ""; position: absolute; width: 100%; height: 20px; left: 0; bottom: -20px; background: radial-gradient(white 0%, white 70%, rgba(255,255,255,0) 70%, rgba( 255,255,255,0) 100%) 0 -10px; background-size: 20px 20px; background-repeat: repeat-x; ) .menu-main li (display: inline-block;) .menu-main a ( text-decoration: none; display: inline-block; margin: 0 15px; padding: 10px 30px; font-family: "PT Sans Caption", sans-serif; color: #777777; transition: .3s linear; position: relative; ) .menu -main a:before, .menu-main a:after ( content: ""; position: absolute; top: calc(50% - 3px); width: 6px; height: 6px; border-radius: 50%; background: #F58262; opacity: 0; transition: .5s ease-in-out; ) .menu-main a:before (left: 5px;) .menu-main a:after (right: 5px;) .menu-main a. current:before, .menu-main a.cur rent:after, .menu-main a:hover:before, .menu-main a:hover:after (opacity: 1;) .menu-main a.current, .menu-main a:hover (color: #F58262; ) @media(max-width:680px) ( .menu-main li (display: block;) )4. Responsive Ribbon Menu
@import url("https://fonts.googleapis.com/css?family=PT+Sans+Caption"); .top-menu ( margin: 0 60px; position: relative; background: #5A394E; box-shadow: inset 1px 0 0 rgba(255,255,255,.1), inset -1px 0 0 rgba(255,255,255,.1), inset 150px 0 150px -150px rgba(255,255,255,.12), inset -150px 0 150px -150px rgba(255,255,255,.12); ) ; z-index: 2; left: 0; width: 100%; height: 3px; ) .top-menu:before ( top: 0; border-bottom: 1px dashed rgba(255,255,255,.2); ) .top- menu:after ( bottom: 0; border-top: 1px dashed rgba(255,255,255,.2); ) .menu-main ( list-style: none; padding: 0; margin: 0; text-align: center; ) . menu-main:before, .menu-main:after ( content: ""; position: absolute; width: 50px; height: 0; top: 8px; border-top: 18px solid #5A394E; border-bottom: 18px solid # 5A394E; transform: rotate(360deg); z-index: -1; ) .menu-main:before ( left: -30px; border-left: 12px solid rgba(255, 255, 255, 0); ) .menu- main:after ( right: -30px; border-right: 12px solid rgba(2 55, 255, 255, 0); ) .menu-main li ( display: inline-block; margin-right: -4px; ) .menu-main a ( text-decoration: none; display: inline-block; padding: 15px 30px; font-family: "PT Sans Caption", sans-serif; color: white; transition: .3s linear; ) .menu-main a.current, .menu-main a:hover (background: rgba(0,0,0,.2);) @media (max-width: 680px) ( .top-menu (margin: 0;) .menu-main li ( display: block; margin-right: 0; ) .menu-main:before, .menu-main:after (content: none;) .menu-main a (display: block;) )5. Responsive menu with a logo in the middle
@import url("https://fonts.googleapis.com/css?family=Arimo"); .top-menu ( position: relative; background: rgba(34,34,34,.2); ) .menu-main ( list-style: none; margin: 0; padding: 0; ) .menu-main:after ( content: ""; display: table; clear: both; ) .left-item (float: left;) .right-item (float: right;) .navbar-logo ( position: absolute; left: 50%; top : 50%; transform: translate(-50%,-50%); ) .menu-main a ( text-decoration: none; display: block; line-height: 80px; padding: 0 20px; font-size: 18px ; letter-spacing: 2px; font-family: "Arimo", sans-serif; font-weight: bold; color: white; transition: .3s linear; ) .menu-main a:hover (background: rgba(0, 0,0,.3);) @media (max-width: 830px) ( .menu-main ( padding-top: 90px; text-align: center; ) .navbar-logo ( position: absolute; left: 50% ;top: 10px; transform: translateX(-50%); ) .menu-main li ( float: none; display: inline-block; ) .menu-main a ( line-height: normal; padding: 20px 15px; font -size: 16px; ) ) @media (max-width: 630px) ( .menu-main li (display: block;) )6. Responsive menu with logo on the left
@import url("https://fonts.googleapis.com/css?family=Arimo"); .top-menu ( background: rgba(255,255,255,.5); box-shadow: 3px 0 7px rgba(0,0,0,.3); padding: 20px; ) .top-menu:after ( content: "" ;display: table; clear: both; ) .navbar-logo (display: inline-block;) .menu-main ( list-style: none; margin: 0; padding: 0; float: right; ) .menu-main li (display: inline-block;) .menu-main a ( text-decoration: none; display: block; position: relative; line-height: 61px; padding-left: 20px; font-size: 18px; letter-spacing : 2px; font-family: "Arimo", sans-serif; font-weight: bold; color: #F73E24; transition:.3s linear; ) .menu-main a:before ( content: ""; width: 9px; height: 9px; background: #F73E24; position: absolute; left: 50%; transform: rotate(45deg) translateX(6.5px); opacity: 0; transition: .3s linear; ) .menu-main a:hover:before (opacity: 1;) @media (max-width: 660px) ( .menu-main ( float: none; padding-top: 20px; ) .top-menu ( text-align: center; padding: 20px 0 0 0; ) .menu-main a (padding: 0 10px;) .menu-main a:be fore (transform: rotate(45deg) translateX(-6px);) ) @media (max-width: 600px) ( .menu-main li (display: block;) )In order to make it convenient to navigate the site, you need navigation, which I made using HTML and CSS scripts. As a result of my work, you can see 2 types of menus (vertical and horizontal). And now, I will try to talk about the tasks that, in my opinion, the menu for the site should perform:
Here I will try to present the material on creating the menu as much as possible, get ready, many may have difficulties, at least I had them. So, let's begin!
First of all, I will tell you how to make. First we write the script in the stylesheet:
#navigation ( width: 560px; height: 50px; margin: 0; padding: 0; background-image: url(img/gor_menu.jpg); background-repeat: no-repeat; background-position:center; ) #navigation ul ( list-style: none; margin: 0; padding: 0; ) #navigation ul li ( display: inline; margin: 0px; ) #navigation ul li a ( height:28px; display: block; float: left; color: #333333; text-decoration: none; font-family: Arial; font-size: 12px; font-weight: bold; background-image: url(img/menu_separatorline.jpg); background-repeat: no-repeat; background- position: right center; padding-top: 17px; padding-right: 15px; padding-bottom: 0; padding-left: 15px; ) #navigation ul li a:hover ( color:#FFF; background-image: url(img /button_hover.jpg); background-repeat: repeat-x; background-position: left top; ) #navigation ul li#active a ( background-image: url(img/button_hover.jpg); background-repeat: repeat-x ; background-position: left top; )
Don't worry, there's nothing wrong with this code. To make it clearer to you, I’ll write the HTML code for this menu right away:
As you can see, we are dealing with a list, which, without a style sheet, is nothing worthwhile. The div statement calls the variables from the external CSS style sheet, then our list is transformed and turns into a nice horizontal menu in my opinion.
Now you need to explain a little what relates to what, then I think you yourself will figure it out:
- contains the entire menu structure. The top image, which I prepared in advance in Photoshop, will be inserted into it;- contains the frame of the menu itself;