How to set up smartphones and PCs. Informational portal
  • home
  • Security
  • Creating a horizontal menu. How to center horizontal menu

Creating a horizontal menu. How to center horizontal menu

Habr, hello!

There are a lot of good solutions from different specialists on Codepen, and I believe that the best of them should be collected in one place. Therefore, 2 years ago, I began to save interesting scripts on various topics on my computer.

I used to post them in the product group of the cloud IDE mr. Gefest, these were assemblies of 5-8 solutions. But now I have started to accumulate 15-30 scripts in different topics (buttons, menus, tooltips, and so on).

Such large sets should be shown to a larger number of specialists. Therefore, I post them on Habr. I hope they will be useful to you.

In this review, we will look at multi-level menus.

Flat Horizontal Navigation

A beautiful navigation bar with a smoothly appearing submenu. The code is well structured, js is used. Judging by the features used, it works in ie8+.
http://codepen.io/andytran/pen/kmAEy

Material Nav Header w/ Aligned Dropdowns

Responsive link bar with two-column submenu. Everything is done in css and html. Applied css3 selectors which are not supported in ie8.
http://codepen.io/colewaldrip/pen/KpRwgQ

Smooth Accordion Dropdown Menu

Stylish vertical menu with smoothly opening elements. Used transition, transform js code.
http://codepen.io/fainder/pen/AydHJ

Pure CSS Dark Inline Navigation Menu

Dark vertical navigation bar with ionicons icons. javascript is applied. In ie8 it will most likely work without animation.
http://codepen.io/3lv3n_snip3r/pen/XbddOO

Pure CSS3 Mega Dropdown Menu With Animation

Stylish menu with two output formats: horizontal and vertical. Icons and css3 animation are used. In ie8 it will definitely look terrible, but in other browsers everything is cool.
Link to vertical: http://codepen.io/rizky_k_r/full/sqcAn/
Link to horizontal: http://codepen.io/rizky_k_r/pen/xFjqs

CSS3 Dropdown Menu

A horizontal menu with large items and a dropdown list of links. Clean and minimalistic code without js.
http://codepen.io/ojbravo/pen/tIacg

Simple Pure CSS Dropdown Menu

Simple but stylish horizontal menu. Font-awesome is used. Everything works on css and html, without js. Will work in ie8.
http://codepen.io/Responsive/pen/raNrEW

Bootstrap 3 mega-dropdown menu

Great solution for online stores. Displays multiple levels of categories and large images (such as stock items). It is based on boostrap 3.
http://codepen.io/organizedchaos/full/rwlhd/

Flat Navigation

Stylish navigation bar with smooth submenus. In older browsers it will display with problems.
http://codepen.io/andytran/pen/YPvQQN

3D nested navigation

Horizontal menu with very cool animation without js!
http://codepen.io/devilishalchemist/pen/wBGVor

Responsive Mega Menu - Navigation

Horizontal responsive menu. Looks good, but the mobile version is a little lame. Used css, html and js.
http://codepen.io/samiralley/pen/xvFdc

Pure CSS3 Menu

original menu. With simple and clean code without js. Use for "wow" effects.
http://codepen.io/Sonic/pen/xJagi

Full CSS3 Dropdown Menu

Colorful drop-down menu with one level of nesting. Icons from font-awesome, html and css are used.
http://codepen.io/daniesy/pen/pfxFi

Css3 only dropdown menu

Pretty good horizontal menu with three levels of nesting. Works without js.
http://codepen.io/riogrande/pen/ahBrb

Dropdown menus

Minimalistic menu with the original effect of the appearance of a nested list of items. Pleased that this solution is also without javascript.
http://codepen.io/kkrueger/pen/qfoLa

Pure CSS DropDown Menu

A primitive but effective solution. Only css and html.
http://codepen.io/andornagy/pen/xhiJH

Pull Menu - Menu Interaction Concept

An interesting menu concept for a mobile phone. I haven't seen this yet. Used html, css and javascript.
http://codepen.io/fbrz/pen/bNdMwZ

Make Simple Dropdown Menu

Clean and simple code, no js. It will definitely work in ie8.
http://codepen.io/nyekrip/pen/pJoYgb

Pure CSS dropdown

The solution is not bad, but too many classes are used. I am glad that there is no js.
http://codepen.io/jonathlee/pen/mJMzgR

Drop Down Menu

Nice vertical menu with minimal javascript code. jQuery is not used!
http://codepen.io/MeredithU/pen/GAinq

CSS 3 Dropdown Menu

A horizontal menu with additional captions can decorate your site well. The code is simple and clear. Javascript is not applied.
http://codepen.io/ibeeback/pen/qdEZjR

Beautiful solution with lots of code (html, css and js). There are 3 submenu formats. For online stores, the solution is well suited.
http://codepen.io/martinridgway/pen/KVdKQJ

CSS3 Menu Dropdowns (special solution)!

Dark horizontal menu with thirteen (13) animation options! Definitely recommend to read, useful in everyday life.
http://codepen.io/cmcg/pen/ofFiz

P.S.
I hope you enjoyed the assembly of 23 solutions. If you want to continue reading them, then take the survey below.
All pleasant work.

If your website is not limited to a single web page, then you should consider adding a navigation bar (menu). A menu is a section of a website designed to help the visitor navigate the site. Any menu is a list of links leading to the internal pages of the site. The easiest way to add a navigation bar to your site is to create a menu using CSS and HTML.

Vertical menu

The first step in creating a vertical menu is to create a bulleted list. We will also need to be able to identify the list, so we will add an id attribute to it with the id "navbar". Each element

  • our list will contain one link:

    Our next task is to reset the default list styles. We need to remove the outer and inner indents from the list itself and the markers from the list items. Then set the desired width:

    #navbar ( margin: 0; padding: 0; list-style-type: none; width: 100px; )

    Now it's time to style the links themselves. We will add a background color to them, change the text parameters: color, size and saturation of the font, remove the underline, add small indents and redefine the display element from inline to block. Additionally, the left and bottom frames were added to the list items.

    The most important part of our changes is the redefinition of inline elements to block elements. Now our links take up the entire available space of the list items, meaning we no longer need to hover over the exact text to follow the link.

    #navbar a ( background-color: #949494; color: #fff; padding: 5px; text-decoration: none; font-weight: bold; border-left: 5px solid #33ADFF; display: block; ) #navbar li ( border-left: 10px solid #666; border-bottom: 1px solid #666; )

    We have combined all the code above into one example, now by clicking on the try button, you can go to the example page and see the result:

    Document's name

    Try »

    When you move the mouse cursor over a menu item, its appearance can change, drawing the user's attention to itself. You can create such an effect using the :hover pseudo-class.

    Let's go back to our earlier vertical menu example and add the following rule to the stylesheet:

    #navbar a:hover ( background-color: #666; border-left: 5px solid #3333FF; ) Try »

    Horizontal menu

    In the previous example, we looked at the vertical navigation bar, which is most often found on websites to the left or right of the main content area. However, menus with navigation links are also often located horizontally at the top of a web page.

    A horizontal menu can be created by styling a regular list. Display property for elements

  • you need to assign the value inline so that the list items are located one after the other.

    To arrange menu items horizontally, first create a bulleted list with links:

    Let's write a couple of rules for our list that reset the style used for lists by default, and redefine the list items from block to inline:

    #navbar ( margin: 0; padding: 0; list-style-type: none; ) #navbar li ( display: inline; ) Try »

    Now we just need to define the styling for our horizontal menu:

    #navbar ( margin: 0; padding: 0; list-style-type: none; border: 2px solid #0066FF; border-radius: 20px 5px; width: 550px; text-align: center; background-color: #33ADFF; ) #navbar a ( color: #fff; padding: 5px 10px; text-decoration: none; font-weight: bold; display: inline-block; width: 100px; ) #navbar a:hover ( border-radius: 20px 5px ; background-color: #0066FF; ) Try »

    Drop-down menu

    The menu we will create will have main navigation links located in the horizontal navigation bar and sub-items that will only be displayed when the mouse cursor is hovered over the menu item to which these sub-items belong.

    First we need to create the HTML structure of our menu. We will place the main navigation links in a bulleted list:

    We will place sub-items in a separate list by nesting it in an element

  • , which contains the parent link relative to the subitems. Now we have a clear structure for our future navigation bar:

    Try »

    Now let's start writing the CSS code. The first step is to hide the list with sub-items with a display: none; declaration so that they don't show up on the web page all the time. To display sub-items, we need that when hovering over an element

  • the list has been converted to a block element again:

    #navbar ul ( display: none; ) #navbar li:hover ul ( display: block; )

    We remove the default indents and markers from both lists. We make list elements with navigation links floating, forming a horizontal menu, but for list elements containing sub-items we set float: none; so that they appear below each other.

    #navbar, #navbar ul ( margin: 0; padding: 0; list-style-type: none; ) #navbar li ( float: left; ) #navbar ul li ( float: none; )

    Next, we need to make sure that our submenu dropdown doesn't push the content below the navigation bar down. To do this, we will set the list items to position: relative; , but a list containing subitems position: absolute; and add a top property with a value of 100% so that the absolutely positioned submenu appears exactly below the link.

    #navbar ul ( display: none; position: absolute; top: 100%; ) #navbar li ( float: left; position: relative; ) #navbar ( height: 30px; ) Try »

    The height for the parent list was added on purpose, since browsers do not consider floating content as element content, without adding a height, our list will be ignored by the browser and the content following the list will wrap around our menu.

    Now we just need to style both of our lists and our dropdown menu will be ready:

    #navbar ul ( display: none; background-color: #f90; position: absolute; top: 100%; ) #navbar li:hover ul ( display: block; ) #navbar, #navbar ul ( margin: 0; padding: 0; list-style-type: none; ) #navbar ( height: 30px; background-color: #666; padding-left: 25px; min-width: 470px; ) #navbar li ( float: left; position: relative; height: 100%; ) #navbar li a ( display: block; padding: 6px; width: 100px; color: #fff; text-decoration: none; text-align: center; ) #navbar ul li ( float: none; ) #navbar li:hover ( background-color: #f90; ) #navbar ul li:hover ( background-color: #666; )

    Hello dear readers of my blog! Today's article will be very useful for beginners. Since today we will be designing a simple horizontal menu. Before we proceed directly to the layout, I want to say a few words about why I decided to choose this particular topic for the article.

    In fact, everything is quite simple, when I was thinking about the topic of the next lesson for the site, I began to recall and analyze my experience in studying layout, what I had to face at the initial stage of becoming myself as a layout designer, which was most incomprehensible to me when studying this area etc. I asked myself all these questions in order to better understand what might be interesting to a person who starts his way as a layout designer. And personally, as soon as I started learning layout, most of all I had questions about the layout of various menus, especially when it comes to multi-level menus. And so today we will talk about the menu, and more specifically about the horizontal menu. So let's start!

    Let's start layout of our horizontal menu!

    As you probably guess, the first thing we need to do is to create an html page with standard markup and include a style file to it. I will not dwell on this step in detail, because I still hope that you are not so beginner as to tell you in detail what body and head are and how styles are included. Let me just say that in addition to the styles for our menu, I will write the simplest reset to the css file in order to reset the styles and achieve the same display of indents in all browsers. This is how my simplest reset looks like:

    I won’t say anything about zeroing styles yet, since in fact this is a topic for another article, the only thing you need to know about the above code is that thanks to this code, all page elements that we will write will have their margins and padding, we need to do this so that our page looks the same in all browsers.

    So what do we have at this stage? We have an html page with standard markup:

    Horizontal menu

    And we have a style file connected to this page (I have style.css), with the following content:

    The next step is to create the html markup for our menu.

    Creating the markup for the menu

    In our markup, we will use the new tag

  • Top Related Articles