Home > Web Front-end > JS Tutorial > body text

HTML, CSS and jQuery: Make a beautiful navigation menu

WBOY
Release: 2023-10-24 08:23:23
Original
1441 people have browsed it

HTML, CSS and jQuery: Make a beautiful navigation menu

HTML, CSS and jQuery: Make a beautiful navigation menu

Navigation menu plays a very important role in web design, it not only provides visitors Navigation functions can also increase the user experience of the website. This article will introduce how to use HTML, CSS and jQuery to make a beautiful navigation menu, with specific code examples.

1. HTML structure

First, we need to use HTML to create the structure of the navigation menu. The following is a simple HTML navigation menu template:

<nav class="navigation">
  <ul class="menu">
    <li><a href="#">首页</a></li>
    <li><a href="#">关于我们</a></li>
    <li><a href="#">产品</a></li>
    <li><a href="#">服务</a></li>
    <li><a href="#">联系我们</a></li>
  </ul>
</nav>
Copy after login

In this template, we have used the <nav> element and the <ul> element to create The container of the navigation menu, using the <li> element and the <a> element to create the navigation menu's list items and links.

2. CSS Style

Next, we use CSS to beautify the appearance of the navigation menu. The following is a basic CSS style example:

.navigation {
  background-color: #333;
}

.menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu li {
  display: inline;
}

.menu li a {
  display: block;
  padding: 10px 15px;
  color: #fff;
  text-decoration: none;
}

.menu li a:hover {
  background-color: #555;
}
Copy after login

In this style example, we set the background color of the navigation menu, the style of the list items, the style of the link, etc. You can modify and adjust it according to your needs.

3. jQuery interaction

Finally, we use jQuery to add interactive effects to the navigation menu. The following is a code example that uses jQuery to display the menu when the mouse is hovered:

$(document).ready(function() {
  $('.menu li').hover(function() {
    $(this).find('ul:first').slideDown(100);
  }, function() {
    $(this).find('ul:first').slideUp(100);
  });
});
Copy after login

In this code example, we use the .hover() method to listen for mouse hover events. When the mouse hovers over the list item of the navigation menu, use the .slideDown() method to display the lower-level menu; when the mouse leaves the list item of the navigation menu, use .slideUp() Method to hide lower-level menus.

4. Summary

By using HTML, CSS and jQuery, we can easily create a beautiful navigation menu. Through reasonable structural layout and style design, coupled with some interactive effects, the navigation menu can play a better role in the web page.

The above is a specific code example for making a beautiful navigation menu. You can modify and adjust it according to your needs and preferences to create a unique navigation menu effect. Hope this article is helpful to you!

The above is the detailed content of HTML, CSS and jQuery: Make a beautiful navigation menu. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template