Web888.vn
  • Shop
  • Blog
Đăng nhập
  • Đăng nhập / Đăng ký

Please enter key search to display results.

Home
  • HTML programming
  • Technology News
Create a single level menu with simple HTML

Create a single level menu with simple HTML

  • 24-07-2022
  • Trung Minh
  • 0 Comments

To make a 1-level menu, there are many solutions. You can use UL and LI tags to enclose menu elements. Or you can also create a div tag, inside it is a list of menu elements.

The result of this article will have the following interface:

Note : The menu will be links, so we must use the a tag to attach links to each of its elements.

Mục lục

  • Build HTML for 1 level menu
  • Add CSS for 1 level menu
  • Choose UL and LI tags to build a 1-level menu

Build HTML for 1 level menu

I will choose the solution is to create a div tag to wrap the menus.

 <div class="menu"> <a href="https://web888.vn" title="web888">Trang chủ</a> <a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a> <a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a> <a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a> <a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a> </div> <div class="menu"> <a href="https://web888.vn" title="web888">Trang chủ</a> <a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a> <a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a> <a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a> <a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a> </div> <div class="menu"> <a href="https://web888.vn" title="web888">Trang chủ</a> <a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a> <a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a> <a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a> <a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a> </div> <div class="menu"> <a href="https://web888.vn" title="web888">Trang chủ</a> <a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a> <a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a> <a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a> <a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a> </div> <div class="menu"> <a href="https://web888.vn" title="web888">Trang chủ</a> <a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a> <a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a> <a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a> <a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a> </div>

Now I just need to style the CSS for this HTML to get the desired result.

Add CSS for 1 level menu

Step 1 : I want the menu background to be blue, so I will write CSS for the surrounding div tag.

 .menu{ background: #333 }

Step 2 : Create white font for menus. Add whitespace and increase the spacing between menus.

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

It looks so much better, doesn't it? Now I want to create an effect when moving the mouse on the menus, the background will change to white, and the text color will change to blue.

To create CSS for mouse movement, we use the CSS :hover property.

 .menu a:hover{ color: #333; background: #fdfdfd; }

Choose UL and LI tags to build a 1-level menu

This solution, the HTML structure will be a bit complicated, but later if you want to add submenus, it's a lot easier.

The HTML structure will look like this :

 <ul class="menu"> <li><a href="https://web888.vn" title="web888">Trang chủ</a></li> <li><a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a></li> <li><a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a></li> <li><a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a></li> <li><a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a></li> </ul> <ul class="menu"> <li><a href="https://web888.vn" title="web888">Trang chủ</a></li> <li><a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a></li> <li><a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a></li> <li><a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a></li> <li><a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a></li> </ul> <ul class="menu"> <li><a href="https://web888.vn" title="web888">Trang chủ</a></li> <li><a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a></li> <li><a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a></li> <li><a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a></li> <li><a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a></li> </ul> <ul class="menu"> <li><a href="https://web888.vn" title="web888">Trang chủ</a></li> <li><a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a></li> <li><a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a></li> <li><a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a></li> <li><a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a></li> </ul> <ul class="menu"> <li><a href="https://web888.vn" title="web888">Trang chủ</a></li> <li><a href="https://web888.vn/hoc-c" title=" web888">Học C/C++</a></li> <li><a href="https://web888.vn/hoc-php" title=" web888">Học PHP</a></li> <li><a href="https://web888.vn/hoc-html-css" title=" web888">Học HTML</a></li> <li><a href="https://web888.vn/hoc-javascript" title=" web888">Học Javascript</a></li> </ul>

Step 1 : By default, the ul tag will have CSS padding and margin. Therefore, we will need to reset to make the menu display like part 1. We also don't forget to add a background to it.

 .menu{ margin: 0px; padding: 0px; background: #333 }

Step 2 : Since the li tag displays as a block, one is to convert it to inline, the other is to use float to push it to one side. We should also remove the dots using list-style:none .

I will use float.

 .menu li{ float:left; list-style: none }

Oh, looks like the background is gone. The reason is that we used float:left for li tags, so the height of the menu will no longer depend on the li tag. Let's add overflow:hidden property to .menu and that will solve it.

 .menu{ margin: 0px; padding: 0px; background: #333; overflow: hidden }

Step 3 : Now we just need to style the a tag like part 1.

 .menu a{ display: inline-block; padding: 5px 10px; color:#fff; text-decoration: none; } .menu a:hover{ color: #333; background: #fff; }

The results were as expected.

So, I have completed the tutorial on how to build a 1-level menu with simple HTML and CSS. In this article, I want you to practice your skills in handling each situation when building a menu. Later you will encounter many more complex menu types.

Bài viết liên quan:

Installing PHP and introducing PHP basics
Instructions for using the plugin wp bakery builder (visual composer) to make a landing page
Instructions for installing and activating Office 2013
15 pocket tips in daily life you should know
What is WordPress and why should learn about wordpress?
Install composer use for Xampp on Windows
Guide to debug (debug) when programming C/C++ with Dev C++
Binary integer representation and binary operations
Create Gmail STMP and install for WordPress, Laravel, php…
Install and enable fileinfo extension in PHP 7 linux (centos,ubuntu)
The thing that limits your growth is the relationship you have
10 groups of customers that business people often encounter and how to behave professionally

THÊM BÌNH LUẬN Cancel reply

Dịch vụ thiết kế Wesbite

NỘI DUNG MỚI CẬP NHẬT

Step-by-step guide to installing Microsoft SQL Server and connecting to the database for beginners

Reasons Why People Are Increasingly Inexperienced in Life

PHP Data Types

Table (table) in SQL Server

Basic data types in C

Giới thiệu

web888.vn là chuyên trang chia sẻ và cập nhật tin tức công nghệ, chia sẻ kiến thức, kỹ năng. Chúng tôi rất cảm ơn và mong muốn nhận được nhiều phản hồi để có thể phục vụ quý bạn đọc tốt hơn !

Liên hệ quảng cáo: [email protected]

Kết nối với web888

© web888.vn - Tech888 Co .Ltd since 2019

Đăng nhập

Trở thành một phần của cộng đồng của chúng tôi!
Registration complete. Please check your email.
Đăng nhập bằng google
Đăng kýBạn quên mật khẩu?

Create an account

Welcome! Register for an account
The user name or email address is not correct.

Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our privacy policy.

Registration confirmation will be emailed to you.
Log in Lost your password?

Reset password

Recover your password
Password reset email has been sent.
The email could not be sent. Possible reason: your host may have disabled the mail function.
A password will be e-mailed to you.
Log in Register
×