一、简单立体导航栏效果

在这里插入图片描述

二、代码实现

1.html

代码如下(示例):

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>立体导航栏</title>
        <link rel="stylesheet" href="./style.css" type="text/css">
    </head>
    <body>
        <div class="container">
            <nav>
                <ul>
                    <li>Home</li>
                    <li>Services</li>
                    <li>Products</li>
                    <li>Clients</li>
                    <li>Contact</li>
                </ul>
            </nav>
        </div>
    </body>
</html>

2.css

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Popins",sans-serif;
}
.container{
    background: #ffbdc9;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
nav{
    background: #fff;
    border-radius: 50px;
    padding: 10px;
    box-shadow: 0 25px 20px -20px rgba(0, 0, 0, 0.4);
}
nav ul li{
    list-style: none;
    display: inline-block;
    padding: 13px 35px;
    margin: 10px;
    font-size: 18px;
    font-weight: 500;
    color: #777;
    cursor: pointer;
    position: relative;
    z-index: 2;
    transition: color 0.5s;
}
nav ul li::after{
    content: "";
    background: #f44566;
    width: 100%;
    height: 100%;
    border-radius: 30px;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%,-50%);
    z-index: -1;
    opacity: 0;
    transition: top 0.5s,opacity 0.5s;
}
nav ul li:hover{
    color: #fff;
}
nav ul li:hover::after{
    top: 50%;
    opacity: 1;
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐