使用css浮动完成网页顶部导航,效果图如下:
css代码:
body{
margin: 0;
}
header{
width:100%;
height:40px;
background-color: #0282DD;
line-height: 40px;
}
.logo{
width:45%;
height:60px;
float: left;
}
.logo>img{
width:80px;
height: 100%;
margin-left: 70px;
background-size:cover;
background-position: center;
}
.right{
width: 55%;
/*height:60px;*/
float: right;
}
/*右边第一层div公共样式*/
.right_common{
/*heightl:60px;*/
/*border:1px red solid;*/
float: left;
color: #fff;
background-color:#0282DD;
cursor: pointer;
text-align: center;
box-sizing: initial;
padding-right: 35px;
}
/*ul列表父类div公共样式*/
.code_list,.design_list{
/*width:100%;*/
height:40px;
overflow: hidden;
}
ul{
list-style: none;
text-align: center;
width: 100%;
border-top:2px #fff solid;
}
li{
list-style: none;
margin: 0 auto;
}
/*设置列表显示*/
.design_list:hover{overflow: visible;height:auto;}
.code_list:hover{overflow: visible;height:auto;}
HTML代码:
#
<header>
<div class="logo">
<img src="./img/logo.png" alt="logo去了外太空">
</div>
<div class="right">
<div class="right_common">首页</div>
<div class="right_common code_list">
<span>代码 ▼</span>
<ul class="common">
<li>html</li>
<li>css</li>
<li>javascript</li>
<li>php</li>
</ul>
</div>
<div class="right_common design_list">
<span>设计 ▼</span>
<ul class="common">
<li>网站设计图</li>
<li>网站logo</li>
<li>网站icon</li>
<li>矢量图</li>
</ul>
</div>
<div class="right_common">金币素材</div>
<div class="right_common">排行榜</div>
<div class="right_common">开发者工具</div>
</div>
</header>