I’ve created this simple navbar using html and css, but I want to move "Valhalla" text on top of the other list elements when the screen gets smaller than 850px.
Html:
<nav>
<ul>
<li><a href = "#">
<h1>
<span><i class="fa-solid fa-dumbbell"></i></span>
<span>Valhalla</span>
</a>
</h1>
</li>
<li><a href = "#">The Gym</a></li>
<li><a href = "#">Workouts</a></li>
<li><a href = "#">Coaches</a></li>
<li><a href = "#">Supplements</a></li>
</ul>
</nav>
Css:
nav {
font-family: var(--mono);
font-size: 1rem;
padding: 1rem;
background-color: black;
}
nav a {
text-decoration: none;
color: var(--white);
}
nav a:hover{
color: var(--green);
}
nav ul{
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
flex-flow: row-wrap;
align-items: center;
gap: 1.5rem;
}
nav li:first-child {
margin-right:auto;
}
.menu-btn {
display: none;
}
@media (max-width: 850px){
}
I’ve tried moving it using max-width and flex-basis: 100% so it would take up the space above, but it kinda just moved to the center of the left side of the navbar, not above the other elements of the list.
@media (max-width: 850px){
nav{
max-width: 1200px;
margin: 0 auto;
}
nav li:first-child {
text-align: center;
flex-basis: 100%;
}
2
Answers
You can add
flex-wrap
tonav ul
or change
flex-flow: row-wrap;
toflex-flow: row wrap;
more info about flex-flow
If I got you correctly then all you need to do is add an id to the element tag that you want it to be on top of the others:
and then you can use the ‘z-index’ and set it to 1 in css:
This should work.