1-4 absolute的包裹性
本节编程练习不计算学习进度,请电脑登录imooc.com操作

absolute的包裹性

absolute的包裹性

任务

老师视频里的不同布局写法,不是习题!!不是习题!!!

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>absolute的包裹性</title>
  7. <style>
  8. .box {
  9. padding: 10px;
  10. background-color: #f0f0f0;
  11. }
  12. input {
  13. position: absolute; top: 234px;
  14. width: 160px; height: 32px;
  15. font-size: 100%;
  16. }
  17. </style>
  18. </head>
  19.  
  20. <body>
  21. <div id="box" class="box"><img src="http://img1.sycdn.imooc.com//54447b06000171a002560191.jpg" width="256" height="191"></div>
  22. <input id="button" type="button" value="容器absolute化">
  23. <script>
  24. var eleBox = document.getElementById("box"), eleBtn = document.getElementById("button");
  25. if (eleBox != null && eleBtn != null) {
  26. eleBtn.onclick = function() {
  27. if (this.absolute) {
  28. eleBox.style.position = "";
  29. this.value = "容器absolute化";
  30. this.absolute = false;
  31. } else {
  32. eleBox.style.position = "absolute";
  33. this.value = "容器去absolute";
  34. this.absolute = true;
  35. }
  36. };
  37. }
  38. </script>
  39. </body>
  40. </html>
下一节