Home Web Front-end CSS Tutorial CSS implements first-level navigation bar

CSS implements first-level navigation bar

Mar 22, 2018 pm 01:04 PM
css navigation

This time I will bring you CSS to implement a first-level navigation bar. What are the precautions for implementing a first-level navigation bar with CSS? The following is a practical case, let’s take a look.

Step one: Introduce the css style sheet, create a new layer with the id nav, and use the <ul>, <li>, <a> tags to create the complete effect.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset=&quot;UTF-8&quot;&gt;
        &lt;title&gt;&lt;/title&gt;
        &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/yiji.css&quot;/&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;p id=&quot;nav&quot;&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/p&gt;
    &lt;/body&gt;
&lt;/html&gt;
Copy after login

The second step is to set the CSS style:

1. Set the attributes of nav

#nav{
    width: 500px;
    height: 50px;
    border: 1px solid red;
}
Copy after login
The display effect is as follows:

##2. Clear the dot in front of the <ul> tag

#nav ul{
    list-style: none;
}
Copy after login

3. Set the properties of the <a> tag contained under <ul>

#nav ul li a{
    width: 98px;
    height: 50px;
    float: left;
    border: 1px solid red;
    text-align: center;
    line-height: 50px;
    text-decoration: none;
}
Copy after login

4 .Set the mouse over effect

#nav ul li a:hover{
    background-color: #ABCDEF;
}
Copy after login

Final effect:

Complete HTML code part :

&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset=&quot;UTF-8&quot;&gt;
        &lt;title&gt;&lt;/title&gt;
        &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/yiji.css&quot;/&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;p id=&quot;nav&quot;&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                 
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                 
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                 
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
                 
                &lt;li&gt;&lt;a href=&quot;&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/p&gt;
    &lt;/body&gt;
&lt;/html&gt;
Copy after login

Complete the CSS style code part:

*{
    margin: 0;
    padding: 0;
}
#nav{
    width: 500px;
    height: 50px;
    border: 1px solid red;
    margin: 30px;
}
#nav ul{
    list-style: none;
}
#nav ul li a{
    width: 98px;
    height: 50px;
    float: left;
    border: 1px solid red;
    text-align: center;
    line-height: 50px;
    text-decoration: none;
}
#nav ul li a:hover{
    background-color: #ABCDEF;
}
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other php Chinese websites related articles!

Recommended reading:

The difference between nth-child and nth-of-type in CSS3 and usage skills


css3 Detailed explanation of the new attribute box-sizing


CSS draws a red heart

The above is the detailed content of CSS implements first-level navigation bar. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does placeholder mean in vue What does placeholder mean in vue May 07, 2024 am 09:57 AM

What does placeholder mean in vue

How to write spaces in vue How to write spaces in vue Apr 30, 2024 am 05:42 AM

How to write spaces in vue

How to get dom in vue How to get dom in vue Apr 30, 2024 am 05:36 AM

How to get dom in vue

What does span mean in js What does span mean in js May 06, 2024 am 11:42 AM

What does span mean in js

What does rem mean in js What does rem mean in js May 06, 2024 am 11:30 AM

What does rem mean in js

How to introduce images into vue How to introduce images into vue May 02, 2024 pm 10:48 PM

How to introduce images into vue

What is the function of span tag What is the function of span tag Apr 30, 2024 pm 01:54 PM

What is the function of span tag

What language is the browser plug-in written in? What language is the browser plug-in written in? May 08, 2024 pm 09:36 PM

What language is the browser plug-in written in?

See all articles