居中  line-hight  是上下
         text-line  是左右
 
 实现一个返回顶部的功能:
1 先写好CSS

2 写动作JS

写一个悬浮菜单:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <style>
  7. .pg-header{
  8. margin: 0 auto;
  9. height: 48px;
  10. width:980px;
  11. background-color: aquamarine;
  12. color: coral;
  13. position: fixed;
  14. top: 0;
  15. left: 20px;
  16. right: 20px;
  17. line-height: 48px;
  18. text-align: center;
  19. }
  20. .pg-body{
  21. margin: 0 auto;
  22. background-color: #dddddd;
  23. width:980px;
  24. height: 5000px;
  25. margin-top: 50px;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div class="pg-header">此处为菜单</div>
  31. <div class="pg-body">此处为内容</div>
  32. </body>
  33. </html>

效果:

上下滚动菜单始终固定在顶部

实现一个点赞按钮的效果:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <div style="position: relative;width: 500px;height: 200px;border: 1px solid red; margin: 0 auto;">
  9. <div style="position: absolute;left: 0;bottom: 0;width: 50px;height: 50px;background-color: aquamarine"></div>
  10. </div>
  11. <div style="position: relative;width: 500px;height: 200px;border: 1px solid red; margin: 0 auto;">
  12. <div style="position: absolute;right: 0;top: 0;width: 50px;height: 50px;background-color: aquamarine"></div>
  13. </div>
  14. </body>
  15. </html>

  

效果:

实现一个遮罩层,就是平时的弹出选择框,即模态框:

加透明度:
opacity  设置遮罩层的透明度  0-1 的范围

三层  
设置一个值,谁的大谁在上面:
z-index

实践:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <div style="background-color: white;
  9. /*display: none;*/
  10. z-index: 10;
  11. position: fixed;
  12. height: 400px;
  13. width: 500px;
  14. top: 50%;
  15. left: 50%;
  16. margin-left: -250px;
  17. margin-top: -200px;
  18. border: 1px brown;
  19. ">
  20. <div style="display: inline">姓名</div><input type="text"/>
  21. <div style="display: inline">密码</div><input type="text"/>
  22. </div>
  23. <div style="background-color: blue;
  24. /*display: none;*/
  25. position: fixed;
  26. z-index: 9;
  27. top:0;
  28. bottom: 0;
  29. left: 0;
  30. right: 0;
  31. opacity: 0.5;"></div>
  32.  
  33. <div style="height: 5000px;background-color: coral;"> hehhehhehe</div>
  34. </body>
  35. </html>

  

效果:

图片的问题:
overflow
可以设置隐藏或者自动生成滚动条

设置上右下左的间隔:

伪类:

鼠标移到后应用:
当鼠标移到当前标签上时,就会使得下面的css生效
hover

实践:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <style>
  7. .pg-header{
  8. position: fixed; /* 设置为固定位置*/
  9. right: 0; /*距离右边0*/
  10. left: 0; /*距离左边0*/
  11. top: 0; /*距离上边0*/
  12. height: 48px; /*高度为48像素*/
  13. background-color: #2459a2; /*背景颜色*/
  14. line-height: 48px; /*设置上下居中,和高度一样才能居中*/
  15. }
  16. .pg-body{
  17. margin-top: 50px; /*设置距离顶部50像素,避免menu挡住body*/
  18. }
  19. .w{
  20. width: 980px; /*全局宽度 980像素*/
  21. margin: 0 auto; /*自动居中*/
  22. }
  23. .pg-header .menu{
  24. display: inline-block; /*设置标签为行内块级混合标签,可以设置高度和宽度*/
  25. padding: 0 10px 0 10px; /*设置标签上下左右的距离*/
  26. color: white; /*字体颜色*/
  27. }
  28. .pg-header .menu:hover{ /*此属性是当鼠标移动到此时应用*/
  29. background-color: dodgerblue; /*背景颜色*/
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="pg-header">
  35. <div class="w">
  36. <a class="logo">LOGO</a>
  37. <a class="menu">段子</a>
  38. <a class="menu">1024</a>
  39. <a class="menu">42区</a>
  40. </div>
  41. </div>
  42. <div class="pg-body">
  43. <div class="w">ddddd</div>
  44. </div>
  45. </body>
  46. </html>

渐变色 就是一个非常细的图片一直自动堆叠

高度增加 也是自动堆叠
控制图片怎么堆叠,使用下面的

其实图标都是只用一个图,然后通过调整

就能显示一个图片不同的位置

实践:

  1. <body>
  2. <div style="height: 100px;"></div>
  3. <div style="height: 20px;width:20px;background-image: url(icon_18_118.png);border: 1px solid red"></div>
  4. </body>

显示不同位置:

  1. <body>
  2. <div style="height: 100px;"></div>
  3. <div style="height: 20px;
  4. width:20px;
  5. background-image: url(icon_18_118.png);
  6. background-position-x: 0px;
  7. background-position-y: -58px;
  8. border: 1px solid red"></div>
  9. </body>

相对的位置,如点赞的图案:

有个问题,图片会挡住输入,修改后就好了

实践:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <div class="user-input" style="padding: 5px;">
  9. <div style="display: inline-block;width: 100px;text-align: right;">账号:</div>
  10. <div style="display: inline-block;width: 300px;height:30px;position: relative;">
  11. <input type="text" style="height: 30px;
  12. width: 270px;
  13. padding-right: 30px"></input>
  14. <span style="position:absolute;
  15. right: 6px;
  16. top:10px;
  17. background-image: url(user.jpg);
  18. height: 16px;
  19. width: 16px;
  20. display: inline-block"></span>
  21. </div>
  22. </div>
  23. <div class="passwd-input" style="padding: 5px;">
  24. <div style="display: inline-block;width: 100px;text-align: right;">这是密码:</div>
  25. <div style="display: inline-block;width: 300px;height:30px;position: relative;">
  26. <input type="text" style="height: 30px;
  27. width: 270px;
  28. padding-right: 30px"></input>
  29. <span style="position:absolute;
  30. right: 6px;
  31. top:10px;
  32. background-image: url(i_pwd.jpg);
  33. height: 16px;
  34. width: 16px;
  35. display: inline-block"></span>
  36. </div>
  37. </div>
  38. </body>
  39. </html>

开始 javascript

一门独立的语言
和java没半毛钱关系
 

helloworld

写代码的位置,两种形式:

1在html 文件中:

2 单独文件,引入到html文件中:

先执行js  从上往下读运行
 
js没有完成之前 网页就一直等待js完成,这样对用户就不友好
 
解决办法就是把js放在html尾部
写在body 内部的最下面:

 

写的时候先写 var
斟酌以后确实是全局,再去掉var

定义函数:

在控制台打印日志:
console.log(1)

根据id找到内容:

获取内容:

 
获取子列表:

拼接字符串:

做一个滚动条效果:

实践:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <script>
  7. function func() {
  8. var tag = document.getElementById('i1');
  9. var content = tag.innerText;
  10. var f = content.charAt(0);
  11. var l = content.substring(1,content.length)
  12. var new_content = l + f;
  13. tag.innerText = new_content;
  14. }
  15. setInterval('func()',500);
  16. </script>
  17. </head>
  18. <body>
  19. <div id="i1">欢迎老男孩莅临指导&nbsp</div>
  20. </body>
  21. </html>

效果:

join 添加分隔符

循环:

DOM
做了一个动作就是把文档转换为一个对象

改变数据:
document.getElementById('i1').innerText = 'new数据'
 

 

 

实现模态框:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <style>
  7. .hide{
  8. display: none;
  9. }
  10. .c1{
  11. position: fixed;
  12. left: 0;
  13. right: 0;
  14. top: 0;
  15. bottom: 0;
  16. background-color: black;
  17. opacity: 0.6;
  18. z-index: 9;
  19. }
  20. .c2{
  21. width: 500px;
  22. height: 400px;
  23. background-color: white;
  24. position: fixed;
  25. left: 50%;
  26. right: 50%;
  27. top: 50%;
  28. margin-left: -250px;
  29. margin-top: -100px;
  30. z-index: 10;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div>
  36. <input type="button" value="添加" onclick="ShowModel();"/>
  37. </div>
  38. <!--遮罩层 -->
  39. <div id="i1" class="c1 hide"></div>
  40. <!-- 弹出窗-->
  41. <div id="i2" class="c2 hide">
  42. <p>
  43. <input type="text"/>
  44. <input type="text"/>
  45. </p>
  46. <p>
  47. <input type="button" value="取消" onclick="HideModel();"/>
  48. <input type="button" value="确定" onclick="HideModel();"/>
  49. </p>
  50. </div>
  51. <script>
  52. function ShowModel() {
  53. document.getElementById('i1').classList.remove('hide')
  54. document.getElementById('i2').classList.remove('hide')
  55. }
  56. function HideModel() {
  57. document.getElementById('i1').classList.add('hide')
  58. document.getElementById('i2').classList.add('hide')
  59. }
  60. </script>
  61. </body>
  62. </html>

效果:

 
实现一个全选和取消的功能:
 

分号必须要加,因为线上的时候会把js文件成为一行,必须用分好来断句, 生成一行就是为了节约空间,有专门的压缩工具

实现一个后台管理的简单页面,需要点击菜单显示菜单,可以全选,反选,可以点击有模态框效果:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>管理</title>
  6. <style>
  7. .pg-header{
  8. margin: 0 auto;
  9. height: 48px;
  10. /*width:980px;*/
  11. background-color: #2459a2;
  12. color: coral;
  13. position: fixed;
  14. top: 0;
  15. left: 0;
  16. right: 0;
  17. line-height: 48px;
  18. z-index: 10;
  19. }
  20. .pg-header .logo{
  21. display: inline-block;
  22. margin-left: 50px;
  23. }
  24. .pg-body{
  25. margin-top: 50px;
  26. width:1080px;
  27. height: 2000px;
  28. }
  29. .pg-body .menu{
  30. text-align: center;
  31. width:200px;
  32. border: 1px solid red;
  33. padding: 10px;
  34. background-color: aquamarine;
  35. float: left;
  36. margin: 5px;
  37. }
  38. .pg-body .menu .every-menu{
  39. text-align: center;
  40. display: inline-block;
  41. border: 1px solid red;
  42. width: 180px;
  43. height: 50px;
  44. margin: 5px;
  45. padding: 2px;
  46. line-height: 50px;
  47. }
  48. .pg-body .info{
  49. float: left;
  50. margin: 5px;
  51. border: 1px solid red;
  52. width: 800px;
  53. height: 500px;
  54. }
  55. .pg-body .info .info-menu{
  56. margin: 10px;
  57. }
  58. .pg-body .info-body{
  59. margin: 5px;
  60. /*width: 650px;*/
  61. height: 400px;
  62. border: 1px solid red;
  63. text-align: center;
  64. }
  65. .go-header{
  66. position: fixed;
  67. bottom:20px;
  68. right:20px;
  69. width: 80px;
  70. height: 80px;
  71. background-color: coral;
  72. color: white;
  73. z-index: 11;
  74. cursor: pointer;
  75. }
  76. .hide{
  77. display: none;
  78. }
  79. .c1{
  80. position: fixed;
  81. left: 0;
  82. right: 0;
  83. top: 0;
  84. bottom: 0;
  85. background-color: black;
  86. opacity: 0.6;
  87. z-index: 9;
  88. }
  89. .c2{
  90. width: 500px;
  91. height: 400px;
  92. background-color: white;
  93. position: fixed;
  94. left: 50%;
  95. right: 50%;
  96. top: 50%;
  97. margin-left: -250px;
  98. margin-top: -100px;
  99. z-index: 10;
  100. }
  101. .hide-menu{
  102. display: none;
  103. }
  104. .item .header{
  105. height: 35px;
  106. background-color: #2459a2;
  107. color: white;
  108. line-height: 35px;
  109. }
  110.  
  111. </style>
  112. </head>
  113. <body>
  114. <div class="pg-header">
  115. <a class="logo">LOGO</a>
  116. </div>
  117.  
  118. <div class="go-header" onclick="GoTop();">
  119. <img src="back_top.png" alt="美女" title="返回顶部">
  120. </div>
  121.  
  122. <!--遮罩层 -->
  123. <div id="i1" class="c1 hide"></div>
  124. <!-- 弹出窗-->
  125. <div id="i2" class="c2 hide">
  126. <p>
  127. <div style="margin: 5px;">
  128. <div style="display: inline-block;width: 60px;text-align: right">IP:</div>
  129. <input type="text"/>
  130. </div>
  131. <div style="margin: 5px;">
  132. <div style="display: inline-block;width: 60px;text-align: right">主机:</div>
  133. <input type="text"/>
  134. </div>
  135. </p>
  136. <p>
  137. <div style="display: inline-block;width: 200px;text-align: center">
  138. <input type="button" value="取消" onclick="HideModel();"/>
  139. <input type="button" value="确定" onclick="HideModel();"/>
  140. </div>
  141. </p>
  142. </div>
  143.  
  144. <div class="pg-body">
  145. <div class="menu">
  146. <div class="item">
  147. <div id='m1' class="header" onclick="ChangeMenu('m1');">菜单1</div>
  148. <div class="content hide-menu">
  149. <div>内容1</div>
  150. <div>内容1</div>
  151. <div>内容1</div>
  152. </div>
  153. </div>
  154. <div class="item">
  155. <div id='m2' class="header" onclick="ChangeMenu('m2');">菜单2</div>
  156. <div class="content hide-menu">
  157. <div>内容2</div>
  158. <div>内容2</div>
  159. <div>内容2</div>
  160. </div>
  161. </div>
  162. <div class="item">
  163. <div id='m3' class="header" onclick="ChangeMenu('m3');">菜单3</div>
  164. <div class="content hide-menu">
  165. <div>内容3</div>
  166. <div>内容3</div>
  167. <div>内容3</div>
  168. </div>
  169. </div>
  170. <div class="item">
  171. <div id='m4' class="header" onclick="ChangeMenu('m4');">菜单4</div>
  172. <div class="content hide-menu">
  173. <div>内容4</div>
  174. <div>内容4</div>
  175. <div>内容4</div>
  176. </div>
  177. </div>
  178. </div>
  179.  
  180. <div class="info">
  181. <div class="info-menu">
  182. <input type="button" value="全选" onclick="CheckAll();"> </input>
  183. <input type="button" value="取消" onclick="CancleAll();"> </input>
  184. <input type="button" value="反选" onclick="ReCheckAll();"> </input>
  185. <input type="button" value="添加" onclick="ShowModel();"> </input>
  186. </div>
  187. <div class="info-body">
  188. <div>
  189. <table>
  190. <thead>
  191. <tr>
  192. <td>选择</td>
  193. <td>主机</td>
  194. <td>IP</td>
  195. <td>备注</td>
  196. </tr>
  197. </thead>
  198. <tbody id="tb">
  199. <tr>
  200. <td><input type="checkbox"/></td>
  201. <td>web101</td>
  202. <td>192.168.8.5</td>
  203. <td></td>
  204. </tr>
  205. <tr>
  206. <td><input type="checkbox"/></td>
  207. <td>web102</td>
  208. <td>192.168.8.6</td>
  209. <td></td>
  210. </tr>
  211. <tr>
  212. <td><input type="checkbox"/></td>
  213. <td>web103</td>
  214. <td>192.168.8.7</td>
  215. <td></td>
  216. </tr>
  217. <tr>
  218. <td><input type="checkbox"/></td>
  219. <td>web104</td>
  220. <td>192.168.8.8</td>
  221. <td></td>
  222. </tr>
  223. <tr>
  224. <td><input type="checkbox"/></td>
  225. <td>web105</td>
  226. <td>192.168.8.9</td>
  227. <td></td>
  228. </tr>
  229. </tbody>
  230. </table>
  231. </div>
  232. </div>
  233. </div>
  234. <div style="clear: both;"></div>
  235. </div>
  236. <script>
  237. function CheckAll() {
  238. var tbody = document.getElementById('tb');
  239. var tr_list = tbody.children;
  240. for (var i = 0; i < tr_list.length; i++) {
  241. var curren_tr = tr_list[i];
  242. var checkbox = curren_tr.children[0].children[0];
  243. checkbox.checked = true;
  244. }
  245. }
  246.  
  247. function CancleAll() {
  248. var tbody = document.getElementById('tb');
  249. var tr_list = tbody.children;
  250. for (var i = 0; i < tr_list.length; i++) {
  251. var curren_tr = tr_list[i];
  252. var checkbox = curren_tr.children[0].children[0];
  253. checkbox.checked = false;
  254. }
  255. }
  256.  
  257. function ReCheckAll() {
  258. var tbody = document.getElementById('tb');
  259. var tr_list = tbody.children;
  260. for (var i = 0; i < tr_list.length; i++) {
  261. var curren_tr = tr_list[i];
  262. var checkbox = curren_tr.children[0].children[0];
  263. if (checkbox.checked) {
  264. checkbox.checked = false;
  265. }else{
  266. checkbox.checked = true;
  267. }
  268. }
  269. }
  270.  
  271. function GoTop() {
  272. document.body.scrollTop = 0;
  273. }
  274.  
  275. function ShowModel() {
  276. document.getElementById('i1').classList.remove('hide')
  277. document.getElementById('i2').classList.remove('hide')
  278. }
  279.  
  280. function HideModel() {
  281. document.getElementById('i1').classList.add('hide')
  282. document.getElementById('i2').classList.add('hide')
  283. }
  284.  
  285. function ChangeMenu(nid){
  286. var current_header = document.getElementById(nid);
  287. var item_list = current_header.parentElement.parentElement.children;
  288. for(var i=0;i<item_list.length;i++){
  289. var current_item = item_list[i];
  290. current_item.children[1].classList.add('hide-menu');
  291. }
  292. current_header.nextElementSibling.classList.remove('hide-menu');
  293. }
  294. </script>
  295. </body>
  296. </html>

效果:

 
 
 
 
 
 

day15 CSS JS DOM初探的更多相关文章

  1. HTML,CSS,JS,DOM,jQuery

    HTML 超链接访问顺序 a:link-->a:visited-->a:hover-->a:active.(有顺序) link:表示从未访问过的链接的样式 visited:表示已经访 ...

  2. 转战JS(1) 初探与变量类型、运算符、常用函数与转换

    转战JS(1)初探与变量类型.运算符.常用函数与转换 做为一名.NET后台开发人员,正考滤向Web前端开发转型,之前也写过一代前端代码,可是当再回头看JS,并有转向它的意愿的时候,突然发现:原来JS不 ...

  3. 1. web前端开发分享-css,js入门篇

    关注前端这么多年,没有大的成就,就入门期间积累了不少技巧与心得,跟大家分享一下,不一定都适合每个人,毕竟人与人的教育背景与成长环境心理活动都有差别,但就别人的心得再结合自己的特点,然后探索适合自己的学 ...

  4. css+js+html基础知识总结

    css+js+html基础知识总结 一.CSS相关 1.css的盒子模型:IE盒子模型.标准W3C盒子模型: 2.CSS优先级机制: 选择器的优先权:!important>style(内联样式) ...

  5. web前端开发分享-css,js入门篇(转)

    转自:http://www.cnblogs.com/jikey/p/3600308.html 关注前端这么多年,没有大的成就,就入门期间积累了不少技巧与心得,跟大家分享一下,不一定都适合每个人,毕竟人 ...

  6. jQuery中的ready方法及实现按需加载css,js

    模拟jQuery中的ready方法及实现按需加载css,js 一.ready函数的实现 经常用jQuery类库或其他类库中的ready方法,有时候想想它们到底是怎么实现的,但是看了一下jQuery中的 ...

  7. Js DOM 详解

    DOM事件类 基本概念 DOM事件的级别 1.DOM0 element.onclick = function(){} 2.DOM2 element.addEventListener("cli ...

  8. 用html+css+js实现选项卡切换效果

    文章转载自:http://tongling.github.io/JSCards/ 用html+css+js实现选项卡切换效果 使用之前学过的综合知识,实现一个新闻门户网站上的常见选项卡效果: 文字素材 ...

  9. web前端开发分享-css,js入门篇

    学习没有捷径,但学习是有技巧与方法.   一,css入门篇:   推荐书籍:css哪些事儿,精通css. 理由:css那些事儿,他是一本介绍css基础类的书,是入门的经典读物. 系统的介绍了css的选 ...

随机推荐

  1. ubuntu安装robo3t

    直接在官网下载 解压文件(使用命令 tar -zxvf robo3t-1.2.1-linux-x86_64-3e50a65.tar.gz) 打开解压后的文件,进入bin文件,直接在终端运行 ./rob ...

  2. (已解决)Arduino mega2560 R3插在电脑上没有反应

           OK,话不多说.网上找了一些资料,感觉都说的不够清晰.自己琢磨了下,有了一个简单粗暴的方法. 步骤1:插上Arduino mega2560板子.没有反应. 步骤2:我的电脑-管理-设备管 ...

  3. 微信iOS端无法执行jquery on()方法

    微信iOS端无法执行jquery on()方法,click方法可以, 如下代码是不会执行的: $(function(){ $('body').on('click','.cka',function(){ ...

  4. jquery-weui picker组件实现只选择年月

    var date = new Date() var month = date.getMonth()+1 //获取当前月份 $('#selectTime').picker({ toolbarTempla ...

  5. webstorm下载激活汉化

    下载 官方下载地址:https://www.jetbrains.com/webstorm/ 激活 参考http://blog.csdn.net/it_talk/article/details/5244 ...

  6. C#环形缓冲区(队列)完全实现

    公司项目中经常设计到串口通信,TCP通信,而且大多都是实时的大数据的传输,然后大家都知道协议通讯肯定涉及到什么,封包.拆包.粘包.校验--什么鬼的概念一大堆,说简单点儿就是要一个高效率可复用的缓存区. ...

  7. HDU3874 线段树 + 离线处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3874 , 线段树(或树状数组) + 离线处理 下午做了第一道离线处理的题目(HDU4417),多少有点 ...

  8. 打造颠覆你想象中的高性能,轻量级的webform框架-----如何替换webform的垃圾控件(第一天)

    前文描述: 随着.net  推出 MVC框架以来,webform 与 mvc 的争论一直没有停止过,一直以来 mvc 的 拥护者远远高于 webform,但是webfrom的有些优势又是mvc而无法替 ...

  9. Objective-C try/catch异常处理机制原理。

    try-catch-finaly finally在任何情况下都会执行(不管有没有异常),属于整个体系的附属. 基本思想是跳到捕获锚点,重新执行. http://www.cnblogs.com/mark ...

  10. 2018.5.17 oracle函数查询

    --*********函数*********** --1.显示当前日期 select sysdate from dual; --2.显示当前日期,格式为****年月日,别名为hday select t ...