赞
踩
为xhu.html添加CSS样式,设计实现西华大学主页导航栏的多级菜单,除了本实验明确要求的设置之外,页面效果应尽可能与西华大学首页导航栏一致,主要要求:
友情提示:推荐使用弹性盒布局设计导航栏; 二级菜单的显示与隐藏display属性;二级菜单的定位采用position定位。
- <!DOCTYPE html>
- <html>
-
- <head>
- <meta charset="utf-8" />
- <title>西华大学</title>
- <style>
- * {
- padding: 0;
- margin: 0;
- }
-
- body {
- font-size: 18px;
- color: white;
- }
-
- a {
- text-decoration: none;
- color: white;
- /*color:white;*/
- }
-
- ul {
- position: relative;
- background: #0e6bc2;
- height: 50px;
- width: auto;
- list-style: none;
- }
-
- li {
- background: #0e6bc2;
- min-width: 144px;
- width: auto;
- height: 50px;
- line-height: 50px;
- }
-
- li:hover {
- background-color: #005691;
- }
-
- div {
- box-sizing: border-box;
- /*便于对齐,免受各类型元素padding不一致的影响*/
- }
-
- .nav {
- display: flex;
- justify-content: center;
- flex-wrap: nowrap;
- width: 100%;
- }
-
- .sub-menu {
- display: none;
- }
-
- .menu-item {
- display: block;
- text-align: center;
- }
-
- #bg {
- margin: 0 auto;
- max-width: 1400px;
- }
-
- img {
- width: 100%;
- }
-
- .block {
- display: block;
- }
-
- input {
- outline-style: none;
- border: 1px solid #ccc;
- border-radius: 3px;
- padding: 3px 4px;
- width: 200px;
- font-size: 14px;
- font-weight: 200;
- }
-
- .form {
- color: black;
- margin: 0 auto;
- max-width: 1400px;
- }
-
- #datetime {
- font-size: 20px;
- background: linear-gradient(to right, rgb(53, 177, 72), rgb(118, 7, 7));
- -webkit-background-clip: text;
- color: transparent;
- }
-
- .times {
- letter-spacing: 0.2rem;
- font-size: 1.2rem;
- background-image: -webkit-linear-gradient(left, #961414, #9005e6 10%, #142396 10%, #05e679 50%, #879614);
- -webkit-text-fill-color: transparent;
- -webkit-background-clip: text;
- -webkit-background-size: 200% 100%;
- }
- </style>
-
- <script>
- var user = JSON.parse(localStorage.getItem('user')) || []
- var m = parseInt(localStorage.getItem('times')) || 1;
- console.log(m);
- window.addEventListener("load", () => {
- let item = document.getElementsByClassName('menu-item')
- for (let i = 0; i < item.length; i++) {
- item[i].addEventListener("mouseover", mouserOver)
- item[i].addEventListener("mouseout", mouserOut)
- }
-
- function mouserOver() {
- this.children[1].classList.add('block')
- }
-
- function mouserOut() {
- this.children[1].classList.remove('block')
- }
-
- setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 500);
- document.getElementById('frequency').innerHTML = m
-
- })
- window.addEventListener("beforeunload", () => {
-
- m++;
- console.log(m);
- localStorage.setItem('times', JSON.stringify(m))
- })
-
- nam = document.getElementById("name")
- num = document.getElementById("num")
- tel = document.getElementById("tel")
- nam.value = user.id
- num.value = user.num
- tel.value = user.tel
-
- function local(value) {
- localStorage.setItem('user', JSON.stringify(value))
- }
-
- function add() {
- const nam = {
- id: document.getElementById('name').value,
- num: document.getElementById('num').value,
- tel: document.getElementById('tel').value,
- }
- local(nam)
- }
- </script>
- </head>
-
- <body>
- <ul class="nav">
- <li class="menu-item"><a href="http://www.xhu.edu.cn">学校概况</a>
- <ul class="sub-menu">
- <li><a href="http://www.xhu.edu.cn" target="new">西华简介</a></li>
- <li>历史沿革</li>
- <li>现任领导</li>
- <li>西华标识</li>
- <li>西华影像</li>
- </ul>
- </li>
- <li class="menu-item"><a href="http://www.xhu.edu.cn">机构设置</a>
- <ul class="sub-menu">
- <li>学院</li>
- <li>部门</li>
- </ul>
- </li>
- <li class="menu-item"><a href="http://www.xhu.edu.cn">人才培养</a>
- <ul class="sub-menu">
- <li>师资队伍</li>
- <li>本科教育</li>
- <li>研究生教</li>
- <li>留学生教育</li>
- <li>专科教育</li>
- <li>继续教育</li>
- </ul>
- </li>
- <li class="menu-item"><a href="http://www.xhu.edu.cn">科学研究</a>
- <ul class="sub-menu">
- <li>科研信息</li>
- <li>科研成果</li>
- <li>学科科研平台</li>
- <li>学术期刊</li>
- </ul>
- </li>
- <li class="menu-item"><a href="http://www.xhu.edu.cn">招生就业</a>
- <ul class="sub-menu">
- <li>本专科招生</li>
- <li>研究生招生</li>
- <li>继续教育招生</li>
- <li>就业信息</li>
- </ul>
- </li>
-
- <li class="menu-item"><a href="http://www.xhu.edu.cn">合作交流</a>
- <ul class="sub-menu">
- <li>国际交流与合作</li>
- <li>地方合作</li>
- <li>西华大学科技园</li>
- <li>国际教育学院</li>
- </ul>
- </li>
- <li class="menu-item"><a href="http://www.xhu.edu.cn">公共服务</a>
- <ul class="sub-menu">
- <li>学校校历</li>
- <li>网络服务</li>
- <li>招标投标</li>
- <li>后勤服务</li>
- <li>办公电话</li>
- </ul>
- </li>
- <li class="menu-item"><a href="http://www.xhu.edu.cn">人才招聘</a>
- </li>
- </ul>
- <div id="bg"><img src="images/bg.jpg"></div>
- <div class="form">
- 姓名<input value="" type="text" id="name"> 学号
- <input value="" type="number" id="num"> 电话
- <input value="" type="tel" id="tel">
- <button onclick=add()>提交</button>
- <div id="datetime">时间</div>
- <span class="times">历史浏览次数:<span id="frequency">0</span></span>
- </div>
- </body>
-
- </html>
css:
- <style>
- * {
- padding: 0;
- margin: 0;
- }
-
- body {
- font-size: 18px;
- color: white;
- }
-
- a {
- text-decoration: none;
- color: white;
- /*color:white;*/
- }
-
- ul {
- position: relative;
- background: #0e6bc2;
- height: 50px;
- width: auto;
- list-style: none;
- }
-
- li {
- background: #0e6bc2;
- min-width: 144px;
- width: auto;
- height: 50px;
- line-height: 50px;
- }
-
- li:hover {
- background-color: #005691;
- }
-
- div {
- box-sizing: border-box;
- /*便于对齐,免受各类型元素padding不一致的影响*/
- }
-
- .nav {
- display: flex;
- justify-content: center;
- flex-wrap: nowrap;
- width: 100%;
- }
-
- .sub-menu {
- display: none;
- }
-
- .menu-item {
- display: block;
- text-align: center;
- }
-
- #bg {
- margin: 0 auto;
- max-width: 1400px;
- }
-
- img {
- width: 100%;
- }
-
- .block {
- display: block;
- }
-
- input {
- outline-style: none;
- border: 1px solid #ccc;
- border-radius: 3px;
- padding: 3px 4px;
- width: 200px;
- font-size: 14px;
- font-weight: 200;
- }
-
- .form {
- color: black;
- margin: 0 auto;
- max-width: 1400px;
- }
-
- #datetime {
- font-size: 20px;
- background: linear-gradient(to right, rgb(53, 177, 72), rgb(118, 7, 7));
- -webkit-background-clip: text;
- color: transparent;
- }
-
- .times {
- letter-spacing: 0.2rem;
- font-size: 1.2rem;
- background-image: -webkit-linear-gradient(left, #961414, #9005e6 10%, #142396 10%, #05e679 50%, #879614);
- -webkit-text-fill-color: transparent;
- -webkit-background-clip: text;
- -webkit-background-size: 200% 100%;
- }
- </style>
新增HTML:
- <div class="form">
- 姓名<input value="" type="text" id="name"> 学号
- <input value="" type="number" id="num"> 电话
- <input value="" type="tel" id="tel">
- <button onclick=add()>提交</button>
- <div id="datetime">时间</div>
- <span class="times">历史浏览次数:<span id="frequency">0</span></span>
- </div>
js脚本:
- <script>
- var user = JSON.parse(localStorage.getItem('user')) || []
- var m = parseInt(localStorage.getItem('times')) || 1;
- console.log(m);
- window.addEventListener("load", () => {
- let item = document.getElementsByClassName('menu-item')
- for (let i = 0; i < item.length; i++) {
- item[i].addEventListener("mouseover", mouserOver)
- item[i].addEventListener("mouseout", mouserOut)
- }
-
- function mouserOver() {
- this.children[1].classList.add('block')
- }
-
- function mouserOut() {
- this.children[1].classList.remove('block')
- }
-
- setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 500);
- document.getElementById('frequency').innerHTML = m
-
- })
- window.addEventListener("beforeunload", () => {
-
- m++;
- console.log(m);
- localStorage.setItem('times', JSON.stringify(m))
- })
-
- nam = document.getElementById("name")
- num = document.getElementById("num")
- tel = document.getElementById("tel")
- nam.value = user.id
- num.value = user.num
- tel.value = user.tel
-
- function local(value) {
- localStorage.setItem('user', JSON.stringify(value))
- }
-
- function add() {
- const nam = {
- id: document.getElementById('name').value,
- num: document.getElementById('num').value,
- tel: document.getElementById('tel').value,
- }
- local(nam)
- }
- </script>
测试结果截图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。