1. <div class="wrapper">
    2. <input id="exp1" class="exp" type="checkbox">
    3. <div class="text">
    4. <label class="btn" for="exp1"></label>
    5. 浮动元素是如何定位的
    6. 正如我们前面提到的那样,当一个元素浮动之后,它会被移出正常的文档流,然后向左或者向右平移,一直平移直到碰到了所处的容器的边框,或者碰到另外一个浮动的元素。
    7. 在下面的图片中,有三个红色的正方形。其中有两个向左浮动,一个向右浮动。要注意到第二个向左浮动的正方形被放在第一个向左浮动的正方形的右边。如果还有更多的正方形这样浮动,它们会继续向右堆放,直到填满容器一整行,之后换行至下一行。
    8. </div>
    9. </div>
    10. <div class="wrapper">
    11. <input id="exp2" class="exp" type="checkbox">
    12. <div class="text">
    13. <label class="btn" for="exp2"></label>
    14. 浮动元素是如何定位的
    15. 正如我们前面提到的那样,当一个元素浮动之后,它会被移出正常的文档流,然后向左或者向右平移,一直平移直到碰到了所处的容器的边框,或者碰到另外一个浮动的元素。
    16. </div>
    17. </div>
    1. .wrapper {
    2. display: flex;
    3. margin: 50px auto;
    4. width: 800px;
    5. overflow: hidden;
    6. /* resize: horizontal; */
    7. border-radius: 8px;
    8. padding: 15px ;
    9. box-shadow: 20px 20px 60px #bebebe,
    10. -20px -20px 60px #ffffff;
    11. }
    12. .text {
    13. font-size: 20px;
    14. overflow: hidden;
    15. text-overflow: ellipsis;
    16. text-align: justify;
    17. /* display: flex; */
    18. /* display: -webkit-box;
    19. -webkit-line-clamp: 3;
    20. -webkit-box-orient: vertical; */
    21. position: relative;
    22. line-height: 1.5;
    23. max-height: 4.5em;
    24. transition: .3s max-height;
    25. }
    26. .text::before {
    27. content: '';
    28. height: calc(100% - 26px);
    29. float: right;
    30. }
    31. .text::after {
    32. content: '';
    33. width: 999vw;
    34. height: 999vw;
    35. position: absolute;
    36. box-shadow: inset calc(100px - 999vw) calc(30px - 999vw) 0 0 #fff;
    37. margin-left: -100px;
    38. }
    39. .btn{
    40. position: relative;
    41. float: right;
    42. clear: both;
    43. margin-left: 20px;
    44. font-size: 16px;
    45. padding: 0 8px;
    46. background: #3F51B5;
    47. line-height: 24px;
    48. border-radius: 4px;
    49. color: #fff;
    50. cursor: pointer;
    51. /* margin-top: -30px; */
    52. }
    53. .btn::after{
    54. content:'展开'
    55. }
    56. .exp{
    57. display: none;
    58. }
    59. .exp:checked+.text{
    60. max-height: none;
    61. }
    62. .exp:checked+.text::after{
    63. visibility: hidden;
    64. }
    65. .exp:checked+.text .btn::before{
    66. visibility: hidden;
    67. }
    68. .exp:checked+.text .btn::after{
    69. content:'收起'
    70. }
    71. .btn::before{
    72. content: '...';
    73. position: absolute;
    74. left: -5px;
    75. color: #333;
    76. transform: translateX(-100%)
    77. }