<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
border: 0;
padding: 0;
margin: 0;
box-sizing: border-box;
}
ul {
list-style: none;
}
#ad {
width: 502px;
height: 400px;
border: 1px solid gray;
margin: 0 auto;
background-color: rgba(157, 157, 157, 0.65);
position: relative;
top: 10px;
}
li {
display: block;
width: 100px;
text-align: center;
padding: 20px 0px;
float: left;
border: 1px solid gray;
border-left: 0px;
border-top: 0px;
background-color: rgba(167, 130, 60, 0.4);
}
li#l1 {
border-right: 0px;
}
/* 这一点是关键点*/
li.col {
border-bottom: 1px solid transparent;
}
</style>
</head>
<body>
<div id="ad">
<ul>
<li>国际新闻</li>
<li>国内新闻</li>
<li>计算机新闻</li>
<li>国内新闻</li>
<li id="l1">计算机新闻</li>
</ul>
</div>
<script>
var aa=document.getElementsByTagName("li");
for(var o of aa){
o.onmouseover=function () {
//这一点是关键点
for(var o1 of aa){
o1.className="";
}
this.className="col";
}
}
</script>
</body>
</html>
结果: