Blogger Information
Blog 28
fans 0
comment 0
visits 13032
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CSS美化留言板案例
手机用户1594223549
Original
671 people have browsed it

一.CSS美化留言板

1.输出结果

2.代码部分

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>CSS美化留言板</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. body {
  15. background-color: lightblue;
  16. max-height: 1120em;
  17. max-width: 1170px;
  18. margin: 0 auto;
  19. padding: 0 30px;
  20. }
  21. h3 {
  22. margin: 20px 10px;
  23. text-align: center;
  24. }
  25. input {
  26. display: block;
  27. width: 100%;
  28. min-height: 200px;
  29. margin-bottom: 20px;
  30. padding: 5px 10px 250px;
  31. }
  32. .list > li {
  33. display: flex;
  34. place-content: space-between;
  35. background-color: lightcoral;
  36. line-height: 36px;
  37. margin-bottom: 5px;
  38. border-radius: 3px;
  39. padding: 0 10px;
  40. }
  41. .list > li > button {
  42. border-radius: 5px;
  43. margin: 5px 0;
  44. border: 1px;
  45. width: 40px;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <h3>留言板</h3>
  51. <input type="text" onkeydown="insertComment(this)" placeholder="请输入您的留言" autofocus/>
  52. <ul class="list"></ul>
  53. </body>
  54. <script>
  55. const insertComment = function (ele) {
  56. if (event.key === 'Enter') {
  57. // 1. 非空判断 event指事件对象
  58. if (ele.value.length === 0) {
  59. alert('留言不能为空')
  60. // 重置焦点
  61. ele.focus();
  62. // 直接返回
  63. return false;
  64. }
  65. // 2. 添加留言
  66. const ul = document.querySelector('.list');
  67. ele.value += `<button onclick="del(this.parentNode)">删除</button>`;
  68. ul.insertAdjacentHTML('afterbegin', `<li>${ele.value}</li>`);
  69. // 3. 清空输入框
  70. ele.value = null;
  71. }
  72. };
  73. // 删除
  74. const del = function(ele) {
  75. return confirm('是否删除?') ? (ele.outerHTML = null) : false;
  76. };
  77. </script>
  78. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的很好, 效果很棒, 继续加油
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post