I’m trying to align the menu in the middle of the page.
I tried putting it on a table. I also tried text-align
.
body {
background-color: #727288;
}
.top-bar-2 {
background-color: #2A0405;
position: fixed;
width: 100%;
height: 50px;
top: 90px;
left: 0;
z-index: 10;
}
.navbar {
overflow: hidden;
background-color: #2A0405;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="top-bar-2">
<div class="navbar">
<a href="#home">Home</a>
<div class="dropdown">
<button class="dropbtn">Sound</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Videos</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Recipes</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</div>
</div>
2
Answers
You can use the
display: flex
property to center the menus horizontally.just add in
.navbar
For the
.navbar
class,Try adding
display:flex;
& either of them below whichever suits your requirement.or
or