7.28

导航条变色

<style type="text/css">
*{
margin:0;
padding:0;
box-sizing: border-box;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
ul{
width:500px;
margin:0 auto;
height:40px;
line-height: 40px;
background: #e4393c;
}
ul>li{
float:left;
}
ul>li>a{
display: inline-block;
width:100px;
text-align: center;
color:#fff;
}
</style>
<body>
<ul>
<li>
<a href="#">首页</a>
</li>
<li>
<a href="#">公司介绍</a>
</li>
<li>
<a href="#">联系我们</a>
</li>
<li>
<a href="#">涉及分类</a>
</li>
<li>
<a href="#">综合设计</a>
</li>
</ul>
<script type="text/javascript">
var li=document.querySelectorAll('ul>li');
console.log(li);
for(var i=0;i<li.length;i++){
li[i].onmouseover=function(){
this.style.background='#fff';
this.firstElementChild.style.color='red';
}
li[i].onmouseout=function(){
this.style.background='#e4393c';
this.firstElementChild.style.color='#fff';
}
}
</script>
</body>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容