Advertisement
milkandcookies

divs slide in on hover

Aug 20th, 2021 (edited)
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <style>
  2.  
  3. .container {
  4. display: flex;
  5. flex-direction: column; /* divs inside form a column instead of a row */
  6. overflow: hidden; /* hides the divs when you initially translate them */
  7. }
  8.  
  9. .box {
  10. flex: 1; /* divs with the class .box will take up an equal amount of space available vertically since we flexed them as a column */
  11. width: 80%; /* the divs’ width is 80% of the main container’s width */
  12. transform: translateX(100%); /* will move the divs completely to the right, outside of the main container and we won’t see them since the overflow is hidden */
  13. display: inline-flex;
  14. }
  15.  
  16. .container:hover .box {
  17. transform: translateX(0); /* when you hover the container the divs will move back to the original position */
  18. }
  19.  
  20. .section {
  21. flex: 1;
  22. height: 100%;
  23. }
  24.  
  25. </style>
  26.  
  27.  
  28. <body>
  29.  
  30. <div class="container">
  31. <div class="item1 box">
  32. <div class="section"></div>
  33. <div class="section"></div>
  34. </div>
  35. <div class="item2 box">
  36. <div class="section"></div>
  37. <div class="section"></div>
  38. </div>
  39. </div>
  40.  
  41. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement