我認(rèn)為使用JavaScript更容易實(shí)現(xiàn)這一點(diǎn),你可以使用元素事件 mouseenter
和 mouseleave
來(lái)實(shí)現(xiàn)樣式的改變,也許這可以幫助你。下面是程式碼:
<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>