导航菜单制作

用原生的html+css编写多级导航菜单,建议在vscode中安装live server插件

最终完成效果
导航菜单制作_第1张图片

准备html

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documenttitle>
    <link rel="stylesheet" href="style.css">
head>
<body>
    <ul>
        <li><a href='#'>Homea>li>
        <li><a href='#'>HTMLa>li>
        <li><a href='#'>CSSa>li>
        <li>
            <a href='#'>Morea>
            <ul class="dropdown">
                <li><a href="#">JavaScripta>li>
                <li><a href="#">Vue3a>li>
                <li><a href="#">TypeScripta>li>
            ul>
        li>
    ul>
body>
html>

在编写的时候,可用一些快捷键,例如:
!+Tab 生成html5的模板
ul.dropdown>li*3>a+Tab 生成多级菜单

编写css

*{
    margin: 0px;
    padding: 0px;
}
ul{
    list-style: none;
    background: black;
    text-align: end;
}
ul li{
    display: inline-block;
    position: relative;
}
ul li a{
    background: #000;
    display: block;
    padding: 20px 45px;
    color: white;
    text-decoration: none;
    font-size: 25px;
    font-weight: blod;
    text-align: center;
}
.dropdown{
    text-align: center;
    color: white;
    display: block;
    width: 230px;
    padding: 20px;
    background: #000;
    position: absolute;
    z-index: 1;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    top: 70px;
    right: 0px;
    display: none;
}
ul li a:hover{
    color: lightseagreen;
}
ul li:hover ul.dropdown{
    display: block;
}
#active{
    color: lightseagreen;
}

你可能感兴趣的:(前端,html5)