The rewritten title is: Change the list title in response to the cursor moving to the list element
P粉131455722
P粉131455722 2023-09-04 23:54:54
0
1
498
<p>I'm creating a linked table and I want to make the table prettier by changing the background color of the table header when I move my mouse over one of the list links. However, I don't know how to change the properties of a container element by affecting its smaller elements. This is my code: </p> <pre class="brush:php;toolbar:false;"><html lang="vi"> <head> <style> .toc-container { max-width: 600px; font-family: "Roboto", sans-serif; background: #deff9d; border-radius: 8px; box-shadow: 0 4px 11px rgba(0, 0, 0, 0.6); } .toc-container h2.index-heading { text-transform: uppercase; font-weight: normal; margin: 0 16px; padding-top: 16px; } .table-of-contents { list-style: none; padding: 0; } .table-of-contents li.author li.blog { background: #222; transition: 400ms; list-style: none; } .table-of-contents li.author{ background-color: green; } .table-of-contents li.author li:nth-of-type(even).blog { background: #2e2e2e; } .table-of-contents li.author li:hover.blog { background: #000; } .table-of-contents li a { text-decoration: none; color: #fff; margin-left: 24px; padding: 16px 0; display: block; } </style> </head> <body> <div class="toc-container"> <h2 class="index-heading">heading</h2> <ul class="table-of-contents"> <li class="author"> <a href="#">Author's name</a> <ul> <li class="blog"> <a href="#">Nháp 1</a> </li> </ul> </li> </ul> </div> </body> </html></pre>
P粉131455722
P粉131455722

reply all(1)
P粉343408929

I think this is easier to achieve using JavaScript, you can use element events mouseenter and mouseleave to achieve style changes, maybe this can help you. Here is the code:

  <script>
    const headerDiv = document.querySelector('.index-heading');
    const blogDiv = document.querySelector('.blog');
    blogDiv.addEventListener('mouseenter', function(e) {
      headerDiv.style.background = 'purple'
    })
    blogDiv.addEventListener('mouseleave', function(e) {
      headerDiv.style.background = '#deff9d'
    })
  </script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template