image.png

html

  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>css实现拖拽布局</title>
  8. <link rel="stylesheet" href="style.css">
  9. </head>
  10. <body>
  11. <div class="column">
  12. <aside class="column-left">
  13. <div class="resize-bar"></div>
  14. <div class="resize-line"></div>
  15. <section class="resize-save">
  16. 左侧的内容,左侧的内容,左侧的内容,左侧的内容
  17. </section>
  18. </aside>
  19. <main class="column-right">
  20. 右侧的内容,右侧的内容,右侧的内容,右侧的内容
  21. </main>
  22. </div>
  23. </body>
  24. </html>

css

  1. .column {
  2. overflow: hidden;
  3. }
  4. .column-left {
  5. height: 400px;
  6. background-color: #fff;
  7. position: relative;
  8. float: left;
  9. }
  10. .column-right {
  11. height: 400px;
  12. padding: 16px;
  13. background-color: #eee;
  14. box-sizing: border-box;
  15. overflow: hidden;
  16. }
  17. .resize-save {
  18. position: absolute;
  19. top: 0;
  20. right: 5px;
  21. bottom: 0;
  22. left: 0;
  23. padding: 16px;
  24. overflow-x: hidden;
  25. }
  26. .resize-bar {
  27. width: 200px;
  28. height: inherit;
  29. resize: horizontal;
  30. cursor: ew-resize;
  31. opacity: 0;
  32. overflow: scroll;
  33. }
  34. /* 拖拽线 */
  35. .resize-line {
  36. position: absolute;
  37. right: 0;
  38. top: 0;
  39. bottom: 0;
  40. border-right: 2px solid #eee;
  41. border-left: 1px solid #bbb;
  42. pointer-events: none;
  43. }
  44. .resize-bar:hover~.resize-line,
  45. .resize-bar:active~.resize-line {
  46. border-left: 1px dashed skyblue;
  47. }
  48. .resize-bar::-webkit-scrollbar {
  49. width: 200px;
  50. height: inherit;
  51. }
  52. /* Firefox只有下面一小块区域可以拉伸 */
  53. @supports (-moz-user-select: none) {
  54. .resize-bar:hover~.resize-line,
  55. .resize-bar:active~.resize-line {
  56. border-left: 1px solid #bbb;
  57. }
  58. .resize-bar:hover~.resize-line::after,
  59. .resize-bar:active~.resize-line::after {
  60. content: '';
  61. position: absolute;
  62. width: 16px;
  63. height: 16px;
  64. bottom: 0;
  65. right: -8px;
  66. background: url(./resize.svg);
  67. background-size: 100% 100%;
  68. }
  69. }