123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- .button {
- display: inline-block;
- padding: 10px 20px;
- background-color: #3498db;
- color: #fff;
- border: none;
- cursor: pointer;
- transition: background-color 0.3s ease;
- }
- .button:hover {
- background-color: #2980b9;
- }
- .dropdown {
- position: relative;
- display: inline-block;
- margin-top: 10px;
- }
- .dropdown-content {
- display: none;
- position: absolute;
- background-color: #f9f9f9;
- min-width: 200px;
- box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
- z-index: 1;
- }
- .dropdown:hover .dropdown-content {
- display: block;
- }
- .dropdown-item {
- padding: 10px;
- cursor: pointer;
- transition: background-color 0.3s ease;
- }
- .dropdown-item:hover {
- background-color: #ddd;
- }
- </style>
- </head>
- <body>
- <div class="dropdown">
- <button class="button">按钮1</button>
- <div class="dropdown-content">
- <div class="dropdown-item">选项1</div>
- <div class="dropdown-item">选项2</div>
- <div class="dropdown-item">选项3</div>
- </div>
- </div>
- <div class="dropdown">
- <button class="button">按钮2</button>
- <div class="dropdown-content">
- <div class="dropdown-item">选项4</div>
- <div class="dropdown-item">选项5</div>
- <div class="dropdown-item">选项6</div>
- </div>
- </div>
- <div class="dropdown">
- <button class="button">按钮3</button>
- <div class="dropdown-content">
- <div class="dropdown-item">选项7</div>
- <div class="dropdown-item">选项8</div>
- <div class="dropdown-item">选项9</div>
- </div>
- </div>
- <div class="dropdown">
- <button class="button">按钮4</button>
- <div class="dropdown-content">
- <div class="dropdown-item">选项10</div>
- <div class="dropdown-item">选项11</div>
- <div class="dropdown-item">选项12</div>
- </div>
- </div>
- <script>
- var dropdowns = document.getElementsByClassName("dropdown");
- for (var i = 0; i < dropdowns.length; i++) {
- dropdowns[i].addEventListener("mouseover", function () {
- this.children[1].style.display = "block";
- });
- dropdowns[i].addEventListener("mouseout", function () {
- this.children[1].style.display = "none";
- });
- }
- </script>
- </body>
- </html>
|