How to set horizontal navigation structure in Html

How to set horizontal navigation structure in Html

This article shares with you two methods of setting up horizontal navigation structures, mainly using list structures.

The method combines a block structure with an inline structure.

Here we first introduce the difference between block elements and inline structures.

(1) The block structure can set attributes such as line height, width (width, height), margin (margin, padding), and border. Inline elements can only set line height, left and right margins, but do not have attributes such as margins, top and bottom padding, and borders.

(2) The block structure is more dominant and does not share a row with other elements. Inline elements can be nested within other elements.

Common block elements include ul, ol, p, form, etc. Common inline elements include meta, img, span, h1-h6, label, etc.

But sometimes, in order to make the block structure have the characteristics of inline elements, or to make the inline elements have the characteristics of block elements, the two are combined. Let's take an example of making an inline element have block element characteristics: the a tag is one of the most important inline tags. Users can access the corresponding page according to the link it specifies. In order to make the elements under the a tag more beautiful, we want to set some attributes for this link, including borders, margins, background colors, etc. We know that these attributes are only available to block structures, so at this moment we want to continue using the inline tag a to accommodate the link content, but we also hope that this inline element can also have the relevant attributes of the block structure.

We can solve this problem by setting "a{display:block}".

Similarly, when we want to use a list to achieve the purpose of setting up horizontal navigation, we hope that each row of the list can be displayed on the same line. At this time, we can also achieve this goal by combining block structure with inline structure.

We just need to add one line of code to the list: list{display:inline;}

Method 2 uses the float attribute setting.

The float attribute can be set to float in two directions, including left and right. To set horizontal navigation, we float the list horizontally to the left. We float it to the left because we hope that after setting the floating, the order of navigation will be horizontal from left to right, that is, from left to right, it is navigation one to navigation four, which is more in line with the habits of more users.

Code:

XML/HTML CodeCopy content to clipboard
  1. <!DOCTYPE html >   
  2. < html >   
  3. < head   lang = "en" >   
  4.      < meta   charset = "UTF-8" >   
  5.      < title > </ title >   
  6.      < style   type = "text/css" >   
  7. ul{
  8. float:right;
  9. }
  10. li{
  11. padding-right:30px;
  12. float:left;
  13. }
  14. a{
  15. margin-left:20px;
  16. font-size:20px;
  17. font-weight:bold;
  18. color:white;
  19. display:block;
  20. border:1px solid black;
  21. width:100px;
  22. text-decoration:none;
  23. text-align:center;
  24. background-color:darkseagreen;
  25. }
  26. a:hover{
  27. color:red;
  28. }
  29.      </ style >   
  30. </ head >   
  31. < body >   
  32. < ul >   
  33.      < li > Navigation 1 </ li >   
  34.      < li > Navigation 2 </ li >   
  35.      < li > Navigation 3 </ li >   
  36. </ ul >   
  37.   
  38. <   href = "#" > Baidu </ a >   
  39. </ body >   
  40. </ html >   

The above is the full content of this article. I hope it will be helpful for everyone’s study.

Original text: http://www.cnblogs.com/xiaoqqmin/p/5317551.html

<<:  CSS isolation issue in Blazor

>>:  MySQL 8.0 can now handle JSON

Recommend

MySQL multi-instance configuration solution

1.1 What is MySQL multi-instance? Simply put, MyS...

How to ensure the overall user experience

Related Articles: Website Design for User Experien...

A brief discussion on the application of Html web page table structured markup

Before talking about the structural markup of web...

CSS injection knowledge summary

Modern browsers no longer allow JavaScript to be ...

Steps to build MHA architecture deployment in MySQL

Table of contents MAH 1. Introduction to MAH Arch...

Analysis of several situations where MySQL index fails

1. Best left prefix principle - If multiple colum...

Using Docker run options to override settings in the Dockerfile

Usually, we first define the Dockerfile file, and...

Analysis of 2 Token Reasons and Sample Code in Web Project Development

Table of contents question: There are 2 tokens in...

Linux tac command implementation example

1. Command Introduction The tac (reverse order of...

Use JS to zoom in and out when you put the mouse on the image

Use JS to zoom in and out when the mouse is on th...

How to process blob data in MySQL

The specific code is as follows: package epoint.m...

Hide HTML elements through display or visibility

Sometimes we need to control whether HTML elements...

Detailed explanation of Vue router routing guard

Table of contents 1. Global beforeEach 1. Global ...

When is it appropriate to use dl, dt, and dd?

dl:Definition list Definition List dt:Definition t...