Вы будете любить flexbox - супер просто и очень полезно.
Для Flexbox требуется родитель и items .
Включите flexbox на на родительском элементе, а затем различные переключатели устанавливаются либо наparent (как в случае justify-content
) или на предметах.
Вот отличная таблица для Flexbox.
Вот фантастический YouTubeучебник .
DEMO:
.navbar {
overflow: hidden;
background-color: #333;
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
z-index: 99999;
text-align: center;
width: 100vw; /* Full width */
display:flex;
justify-content:center;
border:5px solid yellow;
}
/* Links inside the navbar */
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border:1px solid pink;
}
/* Change background on mouse-over */
.navbar a:hover {
background: #ddd;
color: black;
}
<div class="navbar">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
</div>