Responsive horizontal menu with pure CSS3. Vertical menu with CSS Vertical menu with css icons

Good day, dear readers. Today we will look at the topic “ how to make a horizontal menu using HTML and CSS" The menu, as a rule, is located in the header of the site and is a list of links to the most important pages, it is also called main menu. Users will constantly click on these links. How you arrange them and what design you set for the menu will affect user behavior, conversion, their overall impression of your site and, of course, .

HTML code for horizontal menu

Once upon a time, the main menu for a site was made on pictures, tables, flash and perhaps something else, but nowadays there is the most popular and also correct method of creating a menu using “list” tags.

Tags are used to create menus

An example of using html tags to create a menu in the code below:

  • home
  • Services
  • Prices
  • Contacts

Standard CSS styles for horizontal menus

ul ( list-style: none; /*remove list markers*/ margin: 0; /*remove padding*/ padding-left: 0; /*remove padding*/ ) a ( text-decoration: none; /*remove underline link text*/ ) li ( float:left; /*Place the list horizontally to implement the menu*/ margin-right:5px; /*Add indentation to menu items*/ )

We get a ready-made top menu in the header, without any special styles or bells and whistles, this can be called the frame of your future beautiful menu. If you copy and paste this html and css it will look like this.

An example of a frame (template) for your future menu

Everything turned out quite simple, you, of course, want a beautiful main menu right away, but without understanding the basics, you simply will not be able to create a good menu without errors in html and css.

There are also several other CSS methods used to make a menu horizontal besides float:left; eg display:inline-block; or display:flex; , but it is recommended to use the method described above.

Let's fill our menu template with different styles and make it beautiful.

Examples of a beautiful horizontal menu for a website

Now I will give several ready-made examples with a ready-made horizontal menu design.

You can create all the “beauties” for your website yourself, instead of searching on the Internet. The easiest way to do this is to use one of the examples below as a basis.

Simple blue menu with separate items

CSS styles for the top menu

Below are the styles for this menu. The HTML remains the same as in the menu "framework".

Ul ( list-style: none; /*remove list markers*/ margin: 0; /*remove padding*/ padding-left: 0; /*remove padding*/ margin-top:25px; /*make padding at top*/ ) a ( text-decoration: none; /*remove the underlining of the link text*/ background:#30A8E6; /*add a background to the menu item*/ color:#fff; /*change the color of the links*/ padding:10px; /*add indent*/ font-family: arial; /*change the font*/ border-radius:4px; /*add a rounding*/ -moz-transition: all 0.3s 0.01s ease; /*make a smooth transition*/ -o-transition : all 0.3s 0.01s ease; -webkit-transition: all 0.3s 0.01s ease; ) a:hover ( background:#1C85BB;/*add a hover effect*/ ) li ( float:left; /*Place the list horizontally to implement a menu*/ margin-right:5px; /*Add indentation to menu items*/ )

Main menu located on a colored line with a red background

CSS menu styles on color line

ul ( list-style: none; /*remove list markers*/ margin: 0; /*remove padding*/ padding-left: 0; /*remove padding*/ margin-top:25px; /*make padding at top*/ background:#FF4444; /*add a background to the entire menu (by replacing this parameter, you will change the color of the entire menu)*/ height: 50px; /*set the height*/ ) a ( text-decoration: none; /*remove the underlining of the link text* / background:#FF4444; /*add a background to the menu item (by replacing this parameter, you will change the color of all menu items)*/ color:#fff; /*change the color of the links*/ padding:0px 15px; /*add padding*/ font-family: arial; /*change the font*/ line-height:50px; /*align the menu vertically*/ display: block; border-right: 1px solid #F36262; /*add a border to the right*/ -moz-transition : all 0.3s 0.01s ease; /*make a smooth transition*/ -o-transition: all 0.3s 0.01s ease; -webkit-transition: all 0.3s 0.01s ease; ) a:hover ( background:#D43737;/ *add a hover effect*/ ) li ( float:left; /*Place the list horizontally to implement a menu*/ )

Dropdown menu in HTML+CSS

For implementation additional drop-down (drop-down) menu on the site For any menu item, we need to add an additional list of items to the HTML code for any link from the horizontal menu and change the CSS styles. In styles we will use a simple trick - changing the display of the drop-down menu by means of hovering over the item we need in top menu. For example, let’s take the “services” item.

Example of creating a simple dropdown menu

Dropdown Menu HTML Code

  • home
  • Services
    • Service 1
    • Long service 2
    • Service 3
  • Prices
  • Contacts

Dropdown Menu CSS Styles

ul ( list-style: none; /*remove list markers*/ margin: 0; /*remove padding*/ padding-left: 0; /*remove padding*/ margin-top:25px; /*make padding at top*/ background:#819A32; /*add a background to the entire menu*/ height: 50px; /*set the height*/ ) a ( text-decoration: none; /*remove the underlining of the link text*/ background:#819A32; /*add a background to menu item*/ color:#fff; /*change the color of the links*/ padding:0px 15px; /*add indent*/ font-family: arial; /*change the font*/ line-height:50px; /*align the menu by verticals*/ display: block; border-right: 1px solid #677B27; /*add a border to the right*/ -moz-transition: all 0.3s 0.01s ease; /*make a smooth transition*/ -o-transition: all 0.3s 0.01s ease; -webkit-transition: all 0.3s 0.01s ease; ) a:hover ( background:#D43737;/*add a hover effect*/ ) li ( float:left; /*Place the list horizontally to implement a menu* / position:relative; /*set the position for positioning*/ ) /*Styles for the hidden drop-down menu*/ li > ul ( position:absolute; top:25px; display:none; ) /*Make the hidden part visible*/ li:hover > ul ( display:block; width:250px; /*Set the width of the drop-down menu*/ ) li:hover > ul > li ( float:none; /*Remove horizontal positioning* / )

And to understand exactly what services and categories you should have, I recommend that you read the material: .

I tried to tell you as briefly as possible about how to create a main horizontal menu, make several templates, how to add simple styles to it and make it prettier, how to make a drop-down menu for your site. For convenience, I have collected all the menus presented above in one html file, which you can download below. It looks like the screenshot:

Thank you for attention.

There are a lot of ready-made solutions for creating such panels using jQuery, separate plugins and modules for various systems site management.
This is all very good, but is it possible to implement side slide panels using CSS exclusively? Of course you can! But be careful))), keeping in mind that not all browsers support modern CSS3 properties equally well.

Not so long ago, he “produced on-the-mountain” a solution and an example of work. One of the first comments was: “let’s move it to the side...”. Why not? Let's)).

Today I’ll tell you and show you an example of how you can use “CSS magic” to create a completely functional click-to-click menu.
To begin with, according to established tradition, we look at a live example of the panel’s operation, then, together with those who need it, we will consider the entire layout, what, how and why. Anticipating questions, I prepared options for the menu location, both on the left and on the right:

HTML Markup

Let's start the analysis with a panel switch, for which we use a standard flag ():

Place the checkbox at the top of the document, preferably right after the tag . We write the hidden attribute, directly indicating the “hidden” state of this element, and also assign a unique identifier, id="nav-toggle" for example, to link with the for attribute of the tag

I used the tag as a wrapper for the sidebar content