I would like to have a <ul>
inside my <nav>
, in which I need to have a <span>
inside an <a>
tag.
The problem here is that the first li
is vertically not aligned with others and this gives something ugly.
After exploring a bit with the F12 I saw that the span
tag was higher than the a
. Here is a quick preview of the render
.
The table display is here so that space is correctly distributed to each li (I have 5)
I tried to change the position of the span
and of the a
but it didn’t work.
nav {
position: fixed;
top: 0;
left: 0;
background: #dfc8b3;
width: 100%;
text-align: center;
display: table;
margin-bottom: 1em;
}
ul {
display: table-row;
}
li {
list-style: none;
display: table-cell;
font-size: large;
}
a.navlist {
color: black;
float: top;
}
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined"
rel="stylesheet">
<nav>
<ul>
<li class="navlist"><a href="index.html#" class="navlist"><span class="material-symbols-outlined">home</span></a></li>
<li class="navlist"><a href="" class="navlist">li 1</a></li>
</ul>
</nav>
2
Answers
There is a problem with your icons
When displayed exactly as you have shown in your code, we see only text, and that is correctly aligned.
The explanation for your misalignment in your local code is that your icons are different in height. The
vertical-align: middle;
CSS option will correct the position.you can use flexbox for ul element. like this