Is there a way to center the output/result of the HTML code below both horizontally and vertically on the web page using CSS? I have tried the following code but it only centers the output horizontally. Vertical alignment is not working properly. Can someone please assist with this?
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
.container ul li {
vertical-align: middle;
}
li a:hover {
background-color: red;
}
#container {
text-align: center;
}
ul {
display: inline-block;
}
<div id="container">
<ul>
<li><a href="#home">Apple</a></li>
<li><a href="#home">Banana</a></li>
<li><a href="#home">Mango</a></li>
<li><a href="#home">Grapes</a></li>
</ul>
</div>