I'm trying to make an unordered list where the list items are links, not just the text inside them. But this is not valid. When checking my code with https://validator.w3.org/check I receive the message
Element a not allowed as child of element ul in this context.
This is the code:
<html lang="en">
<head>
<meta charset="utf-8">
<title>test</title>
<style>
ul {
list-style:none;
}
a {
text-decoration:none;
color: #212121;
font-size: 1em;
font-family: Arial, Helvetica, sans-serif;
}
#container {
padding:20px;
}
.valid {
background-color:blanchedalmond;
}
.invalid {
background-color:aquamarine;
}
.nav-item {
width:120px;
height:34px;
margin:4px;
line-height:34px;
text-align:center;
border: solid 1px #212121;
}
</style>
</head>
<body>
<div id="container">
<ul>
<li class="valid nav-item"><a href="index.html">valid</a></li>
<a href="index.html"><li class="invalid nav-item">invalid</li></a>
</ul>
</div>
</body>
</html>
The invalid arrangement of <a><li></li></a>
is what I want to achieve behavior-wise with the entire <li>
element being selectable as a link.
If I want to maintain valid code what is the best way to achieve a selectable <li>
?
<li onclick='window.location.href="http://google.com"'>Click Here</li>
– Swab