I am creating navigation menu. I want to use css so that anchor tag is wrapped around li element but anchor tags are inside li element.
Here is html
<ul>
<li><a href="">Uutiset</a></li>
<li><a href="">Foorumi</a></li>
<li><a href="">Kauppa</a></li>
<li><a href="">Messut</a></li>
<li><a href="">Asiakaspalvelu</a></li>
<li><a href="">Nakoislehti</a></li>
<li><a href="">Nae meidat</a></li>
</ul>
here is my less css
ul {
list-style-type: none;
padding: 0;
margin: 0;
li {
padding: 2% 4%;
border: 1px solid green;
a {
text-decoration: none;
display: block;
}
}
}
The only legal element allowed inside a
<ul>is an<li>. You cannot have an anchor wrapped around the<li>. This holds true in HTML5, where an anchor can wrap around other block level elements.What you have in CSS is nearly there, just add:
And your anchor shall fill the entire space of the
<li>.Update for 2022: wrapping your
litags withanchorsis now totally acceptable.