当前位置:   article > 正文

web前端——页面设计_前端页面设计

前端页面设计

为xhu.html添加CSS样式,设计实现西华大学主页导航栏的多级菜单,除了本实验明确要求的设置之外,页面效果应尽可能西华大学首页导航栏一致,主要要求:

  1. 设置导航栏菜单横向分布,当鼠标经过导航栏主菜单项时,显示相应的二级子菜单,一、二级菜单的菜单项宽度一致,见图1;
  2. 导航菜单和展示图应能随浏览器窗口宽度自适应变化,但应能确保导航栏主菜单项始终单行横向分布,并且导航栏一级、二级菜单项中的超链接文本应能始终单行显示且宽度一致,见图2;
  3. 不能更改原HTML文本,包括不能添加任何类名和ID属性!
  4. 编写应用缓存文件,缓存页面中图像;
  5. 在页面图片下方动态显示当前时间,历史浏览次数,添加姓名、学号、电话输入域和一个普通提交按钮(不要使用submit),如果用户曾经提交过信息,则打开页面时在输入域默认显示用户历史信息。(相关布局和元素样式自行设计)。

友情提示:推荐使用弹性盒布局设计导航栏; 二级菜单的显示与隐藏display属性;二级菜单的定位采用position定位。

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>西华大学</title>
  6. <style>
  7. * {
  8. padding: 0;
  9. margin: 0;
  10. }
  11. body {
  12. font-size: 18px;
  13. color: white;
  14. }
  15. a {
  16. text-decoration: none;
  17. color: white;
  18. /*color:white;*/
  19. }
  20. ul {
  21. position: relative;
  22. background: #0e6bc2;
  23. height: 50px;
  24. width: auto;
  25. list-style: none;
  26. }
  27. li {
  28. background: #0e6bc2;
  29. min-width: 144px;
  30. width: auto;
  31. height: 50px;
  32. line-height: 50px;
  33. }
  34. li:hover {
  35. background-color: #005691;
  36. }
  37. div {
  38. box-sizing: border-box;
  39. /*便于对齐,免受各类型元素padding不一致的影响*/
  40. }
  41. .nav {
  42. display: flex;
  43. justify-content: center;
  44. flex-wrap: nowrap;
  45. width: 100%;
  46. }
  47. .sub-menu {
  48. display: none;
  49. }
  50. .menu-item {
  51. display: block;
  52. text-align: center;
  53. }
  54. #bg {
  55. margin: 0 auto;
  56. max-width: 1400px;
  57. }
  58. img {
  59. width: 100%;
  60. }
  61. .block {
  62. display: block;
  63. }
  64. input {
  65. outline-style: none;
  66. border: 1px solid #ccc;
  67. border-radius: 3px;
  68. padding: 3px 4px;
  69. width: 200px;
  70. font-size: 14px;
  71. font-weight: 200;
  72. }
  73. .form {
  74. color: black;
  75. margin: 0 auto;
  76. max-width: 1400px;
  77. }
  78. #datetime {
  79. font-size: 20px;
  80. background: linear-gradient(to right, rgb(53, 177, 72), rgb(118, 7, 7));
  81. -webkit-background-clip: text;
  82. color: transparent;
  83. }
  84. .times {
  85. letter-spacing: 0.2rem;
  86. font-size: 1.2rem;
  87. background-image: -webkit-linear-gradient(left, #961414, #9005e6 10%, #142396 10%, #05e679 50%, #879614);
  88. -webkit-text-fill-color: transparent;
  89. -webkit-background-clip: text;
  90. -webkit-background-size: 200% 100%;
  91. }
  92. </style>
  93. <script>
  94. var user = JSON.parse(localStorage.getItem('user')) || []
  95. var m = parseInt(localStorage.getItem('times')) || 1;
  96. console.log(m);
  97. window.addEventListener("load", () => {
  98. let item = document.getElementsByClassName('menu-item')
  99. for (let i = 0; i < item.length; i++) {
  100. item[i].addEventListener("mouseover", mouserOver)
  101. item[i].addEventListener("mouseout", mouserOut)
  102. }
  103. function mouserOver() {
  104. this.children[1].classList.add('block')
  105. }
  106. function mouserOut() {
  107. this.children[1].classList.remove('block')
  108. }
  109. setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 500);
  110. document.getElementById('frequency').innerHTML = m
  111. })
  112. window.addEventListener("beforeunload", () => {
  113. m++;
  114. console.log(m);
  115. localStorage.setItem('times', JSON.stringify(m))
  116. })
  117. nam = document.getElementById("name")
  118. num = document.getElementById("num")
  119. tel = document.getElementById("tel")
  120. nam.value = user.id
  121. num.value = user.num
  122. tel.value = user.tel
  123. function local(value) {
  124. localStorage.setItem('user', JSON.stringify(value))
  125. }
  126. function add() {
  127. const nam = {
  128. id: document.getElementById('name').value,
  129. num: document.getElementById('num').value,
  130. tel: document.getElementById('tel').value,
  131. }
  132. local(nam)
  133. }
  134. </script>
  135. </head>
  136. <body>
  137. <ul class="nav">
  138. <li class="menu-item"><a href="http://www.xhu.edu.cn">学校概况</a>
  139. <ul class="sub-menu">
  140. <li><a href="http://www.xhu.edu.cn" target="new">西华简介</a></li>
  141. <li>历史沿革</li>
  142. <li>现任领导</li>
  143. <li>西华标识</li>
  144. <li>西华影像</li>
  145. </ul>
  146. </li>
  147. <li class="menu-item"><a href="http://www.xhu.edu.cn">机构设置</a>
  148. <ul class="sub-menu">
  149. <li>学院</li>
  150. <li>部门</li>
  151. </ul>
  152. </li>
  153. <li class="menu-item"><a href="http://www.xhu.edu.cn">人才培养</a>
  154. <ul class="sub-menu">
  155. <li>师资队伍</li>
  156. <li>本科教育</li>
  157. <li>研究生教</li>
  158. <li>留学生教育</li>
  159. <li>专科教育</li>
  160. <li>继续教育</li>
  161. </ul>
  162. </li>
  163. <li class="menu-item"><a href="http://www.xhu.edu.cn">科学研究</a>
  164. <ul class="sub-menu">
  165. <li>科研信息</li>
  166. <li>科研成果</li>
  167. <li>学科科研平台</li>
  168. <li>学术期刊</li>
  169. </ul>
  170. </li>
  171. <li class="menu-item"><a href="http://www.xhu.edu.cn">招生就业</a>
  172. <ul class="sub-menu">
  173. <li>本专科招生</li>
  174. <li>研究生招生</li>
  175. <li>继续教育招生</li>
  176. <li>就业信息</li>
  177. </ul>
  178. </li>
  179. <li class="menu-item"><a href="http://www.xhu.edu.cn">合作交流</a>
  180. <ul class="sub-menu">
  181. <li>国际交流与合作</li>
  182. <li>地方合作</li>
  183. <li>西华大学科技园</li>
  184. <li>国际教育学院</li>
  185. </ul>
  186. </li>
  187. <li class="menu-item"><a href="http://www.xhu.edu.cn">公共服务</a>
  188. <ul class="sub-menu">
  189. <li>学校校历</li>
  190. <li>网络服务</li>
  191. <li>招标投标</li>
  192. <li>后勤服务</li>
  193. <li>办公电话</li>
  194. </ul>
  195. </li>
  196. <li class="menu-item"><a href="http://www.xhu.edu.cn">人才招聘</a>
  197. </li>
  198. </ul>
  199. <div id="bg"><img src="images/bg.jpg"></div>
  200. <div class="form">
  201. 姓名<input value="" type="text" id="name"> 学号
  202. <input value="" type="number" id="num"> 电话
  203. <input value="" type="tel" id="tel">
  204. <button onclick=add()>提交</button>
  205. <div id="datetime">时间</div>
  206. <span class="times">历史浏览次数:<span id="frequency">0</span></span>
  207. </div>
  208. </body>
  209. </html>

css: 

  1. <style>
  2. * {
  3. padding: 0;
  4. margin: 0;
  5. }
  6. body {
  7. font-size: 18px;
  8. color: white;
  9. }
  10. a {
  11. text-decoration: none;
  12. color: white;
  13. /*color:white;*/
  14. }
  15. ul {
  16. position: relative;
  17. background: #0e6bc2;
  18. height: 50px;
  19. width: auto;
  20. list-style: none;
  21. }
  22. li {
  23. background: #0e6bc2;
  24. min-width: 144px;
  25. width: auto;
  26. height: 50px;
  27. line-height: 50px;
  28. }
  29. li:hover {
  30. background-color: #005691;
  31. }
  32. div {
  33. box-sizing: border-box;
  34. /*便于对齐,免受各类型元素padding不一致的影响*/
  35. }
  36. .nav {
  37. display: flex;
  38. justify-content: center;
  39. flex-wrap: nowrap;
  40. width: 100%;
  41. }
  42. .sub-menu {
  43. display: none;
  44. }
  45. .menu-item {
  46. display: block;
  47. text-align: center;
  48. }
  49. #bg {
  50. margin: 0 auto;
  51. max-width: 1400px;
  52. }
  53. img {
  54. width: 100%;
  55. }
  56. .block {
  57. display: block;
  58. }
  59. input {
  60. outline-style: none;
  61. border: 1px solid #ccc;
  62. border-radius: 3px;
  63. padding: 3px 4px;
  64. width: 200px;
  65. font-size: 14px;
  66. font-weight: 200;
  67. }
  68. .form {
  69. color: black;
  70. margin: 0 auto;
  71. max-width: 1400px;
  72. }
  73. #datetime {
  74. font-size: 20px;
  75. background: linear-gradient(to right, rgb(53, 177, 72), rgb(118, 7, 7));
  76. -webkit-background-clip: text;
  77. color: transparent;
  78. }
  79. .times {
  80. letter-spacing: 0.2rem;
  81. font-size: 1.2rem;
  82. background-image: -webkit-linear-gradient(left, #961414, #9005e6 10%, #142396 10%, #05e679 50%, #879614);
  83. -webkit-text-fill-color: transparent;
  84. -webkit-background-clip: text;
  85. -webkit-background-size: 200% 100%;
  86. }
  87. </style>

 新增HTML:

  1. <div class="form">
  2. 姓名<input value="" type="text" id="name"> 学号
  3. <input value="" type="number" id="num"> 电话
  4. <input value="" type="tel" id="tel">
  5. <button onclick=add()>提交</button>
  6. <div id="datetime">时间</div>
  7. <span class="times">历史浏览次数:<span id="frequency">0</span></span>
  8. </div>

js脚本:

  1. <script>
  2. var user = JSON.parse(localStorage.getItem('user')) || []
  3. var m = parseInt(localStorage.getItem('times')) || 1;
  4. console.log(m);
  5. window.addEventListener("load", () => {
  6. let item = document.getElementsByClassName('menu-item')
  7. for (let i = 0; i < item.length; i++) {
  8. item[i].addEventListener("mouseover", mouserOver)
  9. item[i].addEventListener("mouseout", mouserOut)
  10. }
  11. function mouserOver() {
  12. this.children[1].classList.add('block')
  13. }
  14. function mouserOut() {
  15. this.children[1].classList.remove('block')
  16. }
  17. setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 500);
  18. document.getElementById('frequency').innerHTML = m
  19. })
  20. window.addEventListener("beforeunload", () => {
  21. m++;
  22. console.log(m);
  23. localStorage.setItem('times', JSON.stringify(m))
  24. })
  25. nam = document.getElementById("name")
  26. num = document.getElementById("num")
  27. tel = document.getElementById("tel")
  28. nam.value = user.id
  29. num.value = user.num
  30. tel.value = user.tel
  31. function local(value) {
  32. localStorage.setItem('user', JSON.stringify(value))
  33. }
  34. function add() {
  35. const nam = {
  36. id: document.getElementById('name').value,
  37. num: document.getElementById('num').value,
  38. tel: document.getElementById('tel').value,
  39. }
  40. local(nam)
  41. }
  42. </script>

测试结果截图:

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/762588
推荐阅读
相关标签
  

闽ICP备14008679号