HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>导航栏</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<div class="navigation">
<span class="logo"><b>LOGO</b></span>
<ul>
<li><a href="">Home</a></li>
<li><a href="">Produce</a></li>
<li><a href="">Contact</a></li>
<li><a href="">About</a></li>
</ul>
<div class="search">
<input type="text" placeholder="Please enter your msg">
<button>
Search
</button>
</div>
<span class="head_pic"> </span>
<span>
<button>Sign in</button>
<button>Sign up</button>
</span>
</div>
<div class="content">
</div>
<div class="a">
</div>
</div>
</body>
</html>
CSS:
*{
padding: 0;
margin: 0;
}
html,body{
height: 100%;
}
/* 容器 */
.container{
width: 100%;
height: 100%;
}
/* 导航栏 */
.container div.navigation{
width: 100%;
height: 50px;
position: fixed;
display: flex;
justify-content: space-between;
align-items: center;
background-color: whitesmoke;
}
a{
text-decoration: none;
}
ul{
width: 35%;
display: inline;
list-style-type: none;
line-height: 40px;
}
ul li{
float: left;
width: 25%;
text-align: center;
}
li a{
display: block;
padding: 5px;
color: black;
font-size: 18px;
font-family: 'Courier New', Courier, monospace;
}
li a:hover{
background-color: wheat;
}
.navigation span.logo{
width: 5%;
height: 40px;
margin-left: 10px;
padding: 5px;
text-align: center;
font-size: 20px;
letter-spacing: 2px;
font-family:'Times New Roman', Times, serif;
cursor: pointer;
}
.search{
line-height: 40px;
width: 25%;
transition: width 2s;
}
.search:hover{
width: 35%;
}
.search input[type=text]{
float: left;
width: 70%;
height: 40px;
border: none;
background-color: lightgray;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
/* transition: width 2s; */
}
.search button{
float: left;
width: 30%;
height: 40px;
border: none;
background-color: skyblue;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
font-size: 16px;
color: white;
font-family: 'Courier New', Courier, monospace;
cursor: pointer;
}
.navigation span.head_pic{
line-height: 40px;
width: 40px;
background: purple;
background-image: url('cat.jpeg');
background-size: 100% 100%;
background-repeat: no-repeat;
border-radius: 50%;
text-decoration: none;
cursor: pointer;
}
.navigation span{
width: 12%;
margin-right: 10px;
line-height: 40px;
}
.navigation span button{
height: 40px;
width: 70px;
padding: 1px;
border: none;
border-radius: 20px;
font-size: 15px;
color: white;
font-family: 'Courier New', Courier, monospace;
cursor: pointer;
}
span button:first-child{
float: left;
background-color: orange;
}
span button:last-child{
float: right;
background-color:orange;
}
/* 获取焦点时右边不显示 */
div input[type=text]:focus{
outline-width: 1px;
outline-style: solid;
outline-color: skyblue;
}
div input[type=text]::placeholder{
font-size: 14px;
letter-spacing: 1px;
}
div span button:hover{
background-color: rgb(165, 111, 11);
}
/* 中间内容 */
.container div.content{
height: 80%;
/* margin-top: 10%; */
background: none;
background-color: green;
}
/* 展示内容 */
.a{
height: 50%;
background-color: blueviolet;
}
图片资源:
效果图: