一、目录结构
image.png
二、代码
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>商城</title>
<link rel="stylesheet" type="text/css" href="css/common1.css">
<script type="text/javascript" src="js/js1.js"></script>
</head>
<body>
<!--页眉-->
<div class = "header">
<div class="logo">
<img src="image/logo.png">
</div>
<!--onmouseleave 控制鼠标离开事件-->
<div class="menu" onclick="show_menu()" onmouseleave="show_menu1()">
<div class = "menu_title" >
<!-- 一个#号,代表当前页面,但是不刷新页面-->
<a href="###">内容分类</a></div>
<ul id = "menu1" >
<li>现实主义</li>
<li>抽象主义</li>
</ul>
</div>
<div class="auth">
<ul>
<li><a href = "#">登录</a></li>
<li><a href = "#">注册</a></li>
</ul>
</div>
</div>
<!--正文-->
<div class = "content"></div>
<!--页脚-->
<div class = "footer"></div>
</body>
</html>
common.css
*{
padding: 0px;
margin: 0px;
}
.header{
margin: 25px auto 0 50px;
}
.header .menu ul{
display: none;
list-style: none;
}
.header .logo{
float: left;
position: relative;
}
.header .menu{
float: left;
position: relative;
margin-top: 12px;
margin-left: 16px;
}
.header .menu ul li{
margin-top: 20px ;
text-align: center;
}
.header .menu .menu_title{
border-bottom: 1px solid black;
padding-bottom: 20px;
width: 80px;
text-align: center;
}
/*菜单现实折叠*/
/*.header .menu:hover ul{*/
/* display: block;*/
/*}*/
.header .auth{
float: right;
}
.header .auth ul li{
float: left;
margin-right: 50px;
margin-top: 12px;
list-style: none;
}
js1.js
var flag = true;
function show_menu() {
var menu1 = document.getElementById("menu1");
if(flag){
//显示为块状元素
menu1.style.display = "block";
flag = false;
}else{
//把显示的块状元素隐藏
menu1.style.display = "none";
flag = true;
}
}
function show_menu1() {
var menu1 = document.getElementById("menu1");
menu1.style.display = "none";
flag = true;
}
三、成品展示
image.png
网友评论