Make a CSS menu that falls out of the main

Most people who have computers, always trying to connect to the Internet. After that, anyone can visit various sites as a user. This can be a search for information, entertainment, training, games, chatting on forums and more.

By accessing the site page, the user sees its content. It is like the content of the book you are about to read. The content consists of different sets of links that translate the user to other pages of the resource or even to other sites. Such links help users navigate the Internet. Links are grouped into separate blocks representing the site menu.

The functionality of any resource depends largely on what menu on it is used. Site menu can have a different design, have a horizontal or vertical orientation, located at the bottom, top or side, to be hidden, open, drop down, unfolding.

css menu dropdown

Horizontal CSS drop down menu

Horizontal drop-down menu is used to streamline the navigation structure of the site. You should not abuse the number of levels to invest, there should be no more than two. With more levels of user will be much harder to find the necessary information. Next, we consider in more detail the method of creating the menu.

Imagine a CSS menu that falls out of the main horizontal block. Complicate the task and make the CSS a drop-down menu when hovering. There must be some kind of main horizontal block with links representing menu items. After hovering the mouse over these points, additional navigation points should open.

To create a CSS drop down menu, you will need:

  • HTML file;
  • CSS file;
  • image for background.

The image for the background is an auxiliary element to improve the design and make the menu stylish.

css dropdown menu

Create html file

Pages of any site can be static or dynamic. Static page of the site when viewed in a browser is displayed in the form in which it was originally created. A dynamic page is created when it is opened in the browser from separate plug-in pages and additional output of information from the database.But in any case, if you open a page with the source code through a browser, the HTML page of the hypertext markup will be displayed. To create a menu, you need to develop an HTML page and save it to an HTML file. Create a c-menu that falls out of the main in this way. HTML pages can be created in any text editors, but it is better to use specialized ones: Notepad ++ or Adobe Dremweaver CSS. Open an empty page in the editor, enter the necessary code and save it as myindex.html. Comments can be added directly in the code, between special tags that are used in HTML for this purpose.

The page layout when creating a horizontal CSS menu drop-down will differ from the usual standard menu, since you need to add numbered or numbered nested lists <ol> or <ul> to the necessary list elements <li>.

HTML code

It should be noted that in HTML all constructions between <> brackets are called tags. Tags can be single and pair. The pair tag must contain two pairs of brackets <>, and in the second pair the structure inside begins with a slash /. In a pair tag, the first tag is the opening one, and the second one is the closing one.

Create code:

<!doctype html> <!-- Этот тег показывает, что страница создается на HTML 5. -->

<html> <!-- Общий блок, включающий всю HTML-страницу -->

<head> <!-- Служебная невидимая часть HTML-страницы -->

<title>CSS-меню, выпадающее из основного</title> <!-- Название страницы, выводимое в адресной строке браузера -->

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- Кодировка страницы -->

<link rel="stylesheet" href="css/style.css" type="text/css" /> <!-- Присоединение файла стилей -->


<body> <!-- Тело страницы сайта -->

<div class="primer"> <!-- Основной контейнер для вывода меню -->

<ul class="navigator"> <!-- Создание ненумерованного списка для меню -->

<li><a href="#"><span>Главная сайта</span></a></li> <!-- Создание пунктов меню -->

<li><a href="#"><span>Мой пункт меню 1</span></a>

<ul class="vipadnoe"> <!-- CSS-меню, выпадающее из основного -->

<li><a href="#"><span>Мой подпункт 1</span></a></li>

<li><a href="#"><span>Мой подпункт 2</span></a></li>


<li><a href="#"><span>Мой пункт меню 2</span></a>

<ul class="vipadnoe">

<li><a href="#"><span>Мой подпункт 1</span></a></li>

<li><a href="#"><span>Мой подпункт 2</span></a></li>

<li><a href="#"><span>Мой подпункт 3</span></a></li>

<li><a href="#"><span>Мой подпункт 4</span></a></li>

<li><a href="#"><span>Мой подпункт 5</span></a></li>

<li><a href="#"><span>Мой подпункт 6</span></a>

</li></ul></li></ul> </div> </body> </html>

So you can create an infinite number of items and sub-menu. At the very end, close all the paired tags.

vertical dropdown menu on css

Creating a CSS file

In the HTML file, the style.css style file was included, which is necessary not only for the correct positioning of the menu on the website page, but also for giving the menu a beautiful look and creating a unique website design. The CSS file is created in the same editor as the HTML file, but, unlike the HTML page, the user will see only the result of the style file on the page being viewed. In addition, when adding comments to CSS, the / * Comment ... * / construct is used.

CSS code

Create code:

/ * CSS drop down menu * /
body {/ * Style for the body of the site page * /
background: # 0814da; /* Background color */
margin: 0; / * External padding * /
padding: 0; / * Internal padding * /
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; / * Font Family * /
.example {/ * of the whole menu block * /
position: relative; / * Positioning relative to the original place * /
background: # ebecf7 url (../ images / vanbackground.jpg); / * Background with a picture for the whole menu * /
width: 525px; / * Width of the whole menu block * /
height: 384px; / * Height of the whole menu block * /
border: 1px # 000 solid; / * Thickness and border style of the whole menu block * /
margin: 21px auto;
padding: 16px;
/ * styles for menu * /
.navigator, .navigator ul {/ * Block style with unnumbered list * /
list-style: none; / * Cancel markers for the list * /
margin: 0;
padding: 0;
.navigator {/ * Style of the navigation block * /
position: relative;
.navigator ul {/ * Unnumbered List Style * /
height: 0; / * Height * /
left: 0; / * Left * /
overflow: hidden; / * A part of the block is hidden if it does not fit completely in the space provided * /
position: absolute; / * We do absolute positioning * /
top: 47px; / * Above * /
.navigator li {/ * Style of unnumbered items * /
float: left; / * Wrap on the left side * /
position: relative;
.navigator li a {/ * Unnumbered list item style * /
background-color: # 7c75b7; /* Background color */
border: 1px solid # 7c75b7;
color: #fbfbff;
display: block; / * Show by block. * /
font-size: 15px; / * Set the font size * /
line-height: 34px; /* Line spacing */
padding: 6px 21px;
text-decoration: none; / * Text without design * /
transition: 0.6s;
.navigator li: hover> a {/ * Style of items in an unnumbered list when hovering * /
background: # 8fcb38;
border-color: # 7c75b7;
color: #fbfbff;
.navigator li: hover ul.vipadnoe {/ * Hover style drop-down menu * /
height: auto;
width: 181px;
.navigator ul li {/ * Style list and items * /
-moz-transition: 0.7s;
.navigator li ul li {/ * Style item-list-item * /
-moz-transition-delay: 1s;
.navigator li: hover ul li {/ * Mouse hover style * /
.navigator ul li a {/ * Style list-item-link * /
background: # 7c75b7;
border-color: # 7c75b7;
color: #fbfbff;
line-height: 2px;
-moz-transition: 1.7s;
-o-transition: 1.7s;
-webkit-transition: 1.7s;
transition: 1.7s;
.navigator li: hover ul li a {/ * Hovering style item-list-item-link * /
line-height: 36px;
.navigator ul li a: hover {/ * Style list-item plus hover link * /
background: # 8fcb39;
background-image: rgba (41,137,216,0.5);}

css drop down menu when hovering

After the myindex.html and style.css files have been created, they need to be placed in a separate folder. For convenience, we create in the “My Documents” folder a separate demo folder, and in it a CSS folder, where we place the style.css file, and an images folder, where we put the background image specified in the style file.For the myindex.html file, we do not create another separate folder and place it in the demo folder that was originally created. Now, by opening the file myindex.html in the browser, you can see the horizontal CSS menu that appears when you hover. That's all.

In the same way, a vertical drop-down menu is created on the CSS, but only for it it will be necessary to develop a slightly different style file.

Related news

Make a CSS menu that falls out of the main image, picture, imagery

Make a CSS menu that falls out of the main 13

Make a CSS menu that falls out of the main 84

Make a CSS menu that falls out of the main 81

Make a CSS menu that falls out of the main 94

Make a CSS menu that falls out of the main 94

Make a CSS menu that falls out of the main 73

Make a CSS menu that falls out of the main 10

Make a CSS menu that falls out of the main 14

Make a CSS menu that falls out of the main 6