HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>leaning</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="header">
<header>
<nav class="nav_header">
<span class="imgs">Logo</span>
<ul class="nav_header_menu">
<li class="nav_header_item"><a href="#">Home</a></li>
<li class="nav_header_item"><a href="#">Product</a></li>
<li class="nav_header_item"><a href="#">Contact</a></li>
<li class="nav_header_item"><a href="#">Join</a></li>
<div class="nav_header_box"></div>
<div class="nav_header_extend">
<div class="extend_box">
<p>小米6</p>
</div>
<div class="extend_box">
<p>小米6</p>
</div>
<div class="extend_box">
<p>小米6</p>
</div>
<div class="extend_box">
<p>小米6</p>
</div>
<div class="extend_box">
<p>小米6</p>
</div>
</div>
</ul>
<div class="nav_search">
<input type="text" placeholder="请输入搜索内容" maxlength="300px">
<button>搜索</button>
</div>
<div class="nav_btn">
<button>登录</button>
<button>注册</button>
</div>
</nav>
</header>
</div>
<div class="menu">menu</div>
<div class="main">main</div>
<div class="footer">footer</div>
</div>
</body>
</html>
CSS:
/* 网格布局 */
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
/* 网格布局设置 */
.header{grid-area: header;}
.menu{grid-area: menu;}
.main{grid-area: main;}
.right{grid-area: right;}
.footer{grid-area: footer;}
/* 容器布局 */
.container{
display: grid;
grid-template-areas:
'header header header header header header'
'menu main main main main main'
'menu footer footer footer footer footer';
grid-gap: 10px;
grid-template-rows: 70px 432px 87px;
grid-template-columns: 250px 725px;
background-color: #2196F3;
overflow: hidden;
}
.container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px 0;
}
a{
text-decoration: none;
}
header{
position: fixed;
top:0;
left: 0;
width: 100%;
height: 70px;
background-color: #fff;
}
/* 设置顶部导航栏 随父容器*/
.nav_header{
/* 子项目设置 */
height: inherit;
width: inherit;
font-size: 1em;
background-color: aqua;
}
.nav_header span{
float: left;
height: 50px;
width: 50px;
margin:10px 10px;
text-align: center;
background-color: #2196F3;
}
.nav_header ul{
position: absolute;
left: 14%;
display: flex;
justify-content: center;
align-items: center;
width: 500px;
height: inherit;
background-color: aquamarine;
}
.nav_header .nav_search{
position: absolute;
left: 62%;
background-color: #2196F3;
margin: 20px 0;
font-size: 16px;
}
.nav_header .nav_search input{
float: left;
height: 30px;
width: 200px;
border-radius: 5px 0 0 5px;
border: none;
outline: 2px solid orange;
}
.nav_header .nav_search button{
float: right;
height: 30px;
width: 80px;
border: none;
border-radius: 0 5px 5px 0;
letter-spacing: 5px;
background-color: orange;
outline: 2px solid orange;
}
.nav_header .nav_btn{
float: right;
height: 30px;
width: 150px;
margin: 20px 10px;
background-color: rgb(0, 253, 168);
}
.nav_header .nav_btn button{
width: 70px;
height: 30px;
background-color: orange;
border: none;
outline: none;
border-radius: 5px;
}
.nav_header ul li{
display: inline-block;
list-style: none;
width: 25%;
margin: 0 10px;
}
.nav_header .nav_header_item{
line-height: 4em;
font-size: 1.25em;
padding: 5px;
letter-spacing: 2px;
color: #2196F3;
font-family: 'Times New Roman', Times, serif;
}
.nav_header .nav_header_box{
position: absolute;
left: 0;
bottom: 0;
width: calc((100% / 4)*1);
height: 10px;
border-radius: 2px;
transition: .5s;
}
.nav_header .nav_header_extend{
position: absolute;
left: -36%;
bottom: -250%;
width: 100vw;
height: 0;
transform: translateY(-175px);
border-top: 1px solid gray;
box-shadow: 5px 5px 5px #888;
background-color: #fff;
display: flex;
justify-content: center;
align-items: center;
transition: all .5s ease-in-out;
overflow: hidden;
}
.nav_header .extend_box{
width: 20%;
height: inherit;
}
.nav_header .extend_box p{
margin: 77.5px;
}
.nav_header .nav_search input:focus{
outline: 2px solid #FF6377;
}
.nav_header .nav_search input::-webkit-input-placeholder{
font-size: 10;
}
.nav_header ul li:nth-child(1):hover~.nav_header_box{
left: calc((100%/4)*0);
background-color: skyblue;
}
.nav_header ul li:nth-child(2):hover~.nav_header_box{
left: calc((100%/4)*1);
background-color: lightskyblue;
}
.nav_header ul li:nth-child(2):hover~.nav_header_extend{
transform: translateY(0);
height: 175px;
}
.nav_header ul li:nth-child(3):hover~.nav_header_box{
left: calc((100%/4)*2);
background-color: deepskyblue;
}
.nav_header ul li:nth-child(4):hover~.nav_header_box{
left: calc((100%/4)*3);
background-color: blue;
}
效果图:
参考来自: