How not to allocate nested elements when using hover?
Here is a sample code:
ul.left-menu>li:hover{ background:#f5a51a; } https://jsfiddle.net/9c4q72uj/ - full code
what I want to get:
help me fix
How not to allocate nested elements when using hover?
Here is a sample code:
ul.left-menu>li:hover{ background:#f5a51a; } https://jsfiddle.net/9c4q72uj/ - full code
what I want to get:
help me fix
Updated. You can not highlight the "li", and the link itself "a"
body { background: #05294f; } ul.left-menu { list-style: none; margin: 0 0 8px 0; padding: 0; position: relative; } ul.left-menu li { padding: 0 0 0 20px; list-style: none; position: relative; } ul.left-menu li ul li a:before { content: "•"; color: #dadada; font-size: 21px; display: inline-block; vertical-align: middle; margin-right: 10px; } ul.left-menu li a { display: block; font-size: 100%; color: #fff; font-weight: bold; text-decoration: none; padding: 10px; } ul.left-menu li a:hover { background: #f5a51a; } <ul class="left-menu"> <li><a href="/0.html">1</a> <ul> <li><a href="/1.html">1</a> <ul> <li><a href="/1.html">1.1</a> </li> <li><a href="/2.html">1.2</a> </li> </ul> </li> <li><a href="/3.html">3</a> </li> <li><a href="/4.html">4</a> </li> </ul> </li> <li><a href="/5.html">2</a> </li> <li><a href="/6.html">3</a> </li> </ul> body > ul { position: relative; z-index: 0; } li { line-height: 1.5em; } a { display: block; } a:hover:before { content: ""; position: absolute; left: 0; right: 0; height: 1.5em; /* same as line-height */ background: silver; z-index: -1; } <ul class="left-menu"> <li><a href="/0.html">1</a> <ul> <li><a href="/1.html">1</a> <ul> <li><a href="/1.html">1.1</a></li> <li><a href="/2.html">1.2</a></li> </ul> </li> <li><a href="/3.html">3</a></li> <li><a href="/4.html">4</a></li> </ul> </li> <li><a href="/5.html">2</a></li> <li><a href="/6.html">3</a></li> </ul> li { line-height: 1.5em; } a { display: block; } a:hover { background: silver; } <ul class="left-menu"> <li><a href="/0.html">1</a> <ul> <li><a href="/1.html">1</a> <ul> <li><a href="/1.html">1.1</a></li> <li><a href="/2.html">1.2</a></li> </ul> </li> <li><a href="/3.html">3</a></li> <li><a href="/4.html">4</a></li> </ul> </li> <li><a href="/5.html">2</a></li> <li><a href="/6.html">3</a></li> </ul> Source: https://ru.stackoverflow.com/questions/520404/
All Articles