Nav bar with css grid won't align - html

So I'm trying to make a simple nav bar with the logo on the right and the menu and search option on the left. However I cannot figure out how to vertically align them. I feel like this has probably an easy fix but I just can't figure it out. It's for a school asignment.
Here's my html & css
.main-nav {
display: inline;
text-align: center;
padding: 10px 0px 10px 0px;
margin-top: 20px;
}
.main-nav li {
display: inline;
border: none;
}
.main-nav a {
padding: 10px;
}
.navbardesk {
display: grid;
grid-template-areas: "logo links search";
justify-content: center;
background-color: rgba(141, 125, 31, 0.9);
}
.logo {
display: inline-block;
grid-area: logo;
top: auto;
bottom: auto;
}
.main-nav {
grid-area: links;
background-color: transparent;
}
.searchicon {
grid-area: search;
justify-content: center;
}
<div class="navbardesk v-align">
<h1 class="logo">Buurtsuper Leo van der Drift</h1>
<ul class="main-nav" id="js-menu">
<li>Home</li>
<li>Over ons</li>
<li>Kantoren en bedrijven</li>
<li>Bestellen</li>
<li class="nav-links social"> <i class="fab fa-facebook-square"></i> <i class="fab fa-instagram"></i></li>
</ul>
<i class="fas fa-search searchicon"></i>
</div>
it currently looks like this
and I want it to look like this

Remove h1 and ul margin and try the snippet below.
.main-nav {
display: inline;
text-align: center;
padding: 10px 0px 10px 0px;
margin-top: 20px;
}
.main-nav li {
display: inline;
border: none;
}
.main-nav a {
padding: 10px;
}
.navbardesk {
display: grid;
grid-template-areas: "logo links search";
justify-content: center;
background-color: rgba(141, 125, 31, 0.9);
align-items: center;
padding: .5rem;
}
.logo {
display: inline-block;
grid-area: logo;
top: auto;
bottom: auto;
border: solid;
margin: 0;
padding: 0;
}
.main-nav {
grid-area: links;
background-color: transparent;
border: solid;
margin: 0;
}
.searchicon {
grid-area: search;
justify-content: center;
}
<div class="navbardesk v-align">
<h1 class="logo">Buurtsuper Leo van der Drift</h1>
<ul class="main-nav" id="js-menu">
<li>Home</li>
<li>Over ons</li>
<li>Kantoren en bedrijven</li>
<li>Bestellen</li>
<li class="nav-links social"> <i class="fab fa-facebook-square"></i> <i class="fab fa-instagram"></i></li>
</ul>
<i class="fas fa-search searchicon"></i>
</div>

I can't reproduce the error given the code you have provided but adding align-items:center; should do what you want.
.navbardesk{
display: grid;
grid-template-areas: "logo links search";
justify-content: center;
align-items:center;
background-color: rgba(141,125,31,0.9);
}

make sure, your li, a tag should be display: inline-block it will not work margin, padding in inline display.

I believe this will produce exactly what you are looking for, may be some tweaking you still need depending on your situation
#js-menu {
grid-template-columns: repeat(4,200px);
background-color: #f3f3ec;
justify-items: end;
align-items: center;
display: grid;
}
put this line of code along with your other css. there are many ways around!

Related

Why my menu is merging with the input field ? I want it to be responsive

I am new to HTML CSS, can anyone tell me what am I doing wrong?
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--pink: #ff6161;
--white: #fff;
--black: #292828;
--font: "Roboto", sans-serif;
}
header {
min-height: 100px;
max-width: 100%;
background-color: var(--pink);
display: flex;
justify-content: center;
align-items: center;
}
.menu {
max-width: 10rem;
display: flex;
justify-content: center;
align-items: center;
}
.menu-items {
list-style-type: none;
padding-right: 30px;
font-family: var(--font);
font-size: 20px;
}
.menu-items a {
text-decoration: none;
color: var(--black);
}
.search-bar {
width: 700px;
}
.inp {
width: 100%;
height: 2rem;
}
<header>
<div class="search-bar">
<input class="inp" type="text" />
</div>
<ul class="menu">
<i class="fa-solid fa-house"></i>
<li class="menu-items"> Home</li>
<i class="fa-solid fa-store"></i>
<li class="menu-items">Store</li>
<i class="fa-solid fa-headset"></i>
<li class="menu-items">Support</li>
</ul>
</header>
It's because you're using align items: center and justify-content: center in your header at the same time.
You're basically forcing items inside header to move to the center.
In your CSS, when you are modifying the header, you are putting all elements inside of it in the same position.
Something you could to fix this is, give the header a relative position, and then manipulate each element inside the header individually.
Change your display for menu to contents:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--pink: #ff6161;
--white: #fff;
--black: #292828;
--font: "Roboto", sans-serif;
}
header {
min-height: 100px;
max-width: 100%;
background-color: var(--pink);
display: flex;
justify-content: center;
align-items: center;
}
.menu {
max-width: 10rem;
display: contents;
justify-content: center;
align-items: center;
}
.menu-items {
list-style-type: none;
padding-right: 30px;
font-family: var(--font);
font-size: 20px;
}
.menu-items a {
text-decoration: none;
color: var(--black);
}
.search-bar {
width: 700px;
}
.inp {
width: 100%;
height: 2rem;
}
<header>
<div class="search-bar">
<input class="inp" type="text" />
</div>
<ul class="menu">
<i class="fa-solid fa-house"></i>
<li class="menu-items"> Home</li>
<i class="fa-solid fa-store"></i>
<li class="menu-items">Store</li>
<i class="fa-solid fa-headset"></i>
<li class="menu-items">Support</li>
</ul>
</header>
The sum of the text widths of the menu Home Store Support will be greater than max-width: 10rem;
.menu {
display: flex;
justify-content: center;
align-items: center;
}

Space over Navbar

I've got a question. I was trying to code a navbar. It's working perfectly except for the fact that over the navbar there is a big space. So that the navbar is in the middle of the page. I've got no clue what the mistake could be. If u got an idea of what the problem could be and how to solve it, I Would be very pleased. Otherwise, I would be happy to get improvement tips for my code.
.navbar {
position: fixed;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
top: 20%;
width: 100%;
height: 70px;
background-color: black;
-webkit-box-shadow: 0 0 10px var(--shadow);
box-shadow: 0 0 10px var(--shadow);
color: white;
margin-top: 2px;
}
.navbar-nav {
width: 40%;
height: 100%;
padding: 0 7%;
margin: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: space-evenly;
-ms-flex-pack: space-evenly;
justify-content: space-evenly;
list-style: none;
}
.navbar-nav .nav-item {
text-align: center;
}
.navbar-nav .nav-item .item-link {
position: relative;
width: 100%;
padding: 15px 20px;
color: var(--white-smoke);
text-decoration: none;
border-radius: 5px;
border: 1px solid #0e0e0e00;
}
.navbar-nav .nav-item .item-link:hover {
background-color: var(--shadow);
border: 1px solid #4e4e4e4d;
}
.navbar-nav .c:hover #drop-down {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.navbar-nav .c:focus-within #drop-down {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.navbar-nav .c #drop-down {
position: absolute;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
display: none;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
top: 60px;
background-color: var(--white-smoke);
padding: 30px 0;
border-radius: 5px;
text-align: left;
-webkit-box-shadow: 0 0 10px var(--shadow);
box-shadow: 0 0 10px var(--shadow);
-webkit-transform: translateX(-10%);
transform: translateX(-10%);
}
.navbar-nav .c #drop-down .clinks {
display: block;
color: #000;
padding: 5px 0;
text-decoration: none;
padding: 10px 50px 10px 20px;
}
.navbar-nav .c #drop-down .clinks i {
padding: 0 2px;
}
.navbar-nav .c #drop-down .clinks:hover {
background-color: var(--shadow);
}
#media screen and (max-width: 1000px) {
.navbar #brand {
display: none;
}
.navbar .navbar-nav {
width: 100%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<title>DropDown Menu</title>
</head>
<body>
<nav class="navbar">
<ul class="navbar-nav">
<!-- Home -->
<li class="nav-item h">Home
</li>
<!-- Categories -->
<li class="nav-item c">
<a href="#" class="item-link">
<i class="fa fa-angle-down" aria-hidden="true"></i> Investieren</a>
<!-- Dropdown Menu -->
<div id="drop-down">
<a href="#" class="clinks"> <i class="fa fa-code" aria-hidden="true"></i> Web Development
</a>
<a href="#" class="clinks"> <i class="fa fa-android" aria-hidden="true"></i> Mobile Apps
</a>
<a href="#" class="clinks"> <i class="fa fa-adjust" aria-hidden="true"></i> UI / UX
</a>
<a href="#" class="clinks"> <i class="fa fa-database" aria-hidden="true"></i> Database
</a>
<a href="#" class="clinks"> <i class="fa fa-gamepad" aria-hidden="true"></i> Game Development
</a>
</div>
</li>
<!-- Prices -->
<li class="nav-item p">Prices
</li>
<!-- About -->
<li class="nav-item a">About
</li>
</ul>
</nav>
</body>
</html>
Because you have top: 20%; on your .navbar with fixed positioning. You also have margin-top: 2px on your navbar. Remove that and you should be good.
.navbar {
position: fixed;
/*top: 20%;*/
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
width: 100%;
height: 70px;
background-color: black;
-webkit-box-shadow: 0 0 10px var(--shadow);
box-shadow: 0 0 10px var(--shadow);
color: white;
/*margin-top: 2px;*/
}
body {
margin: 0;
}
.navbar-nav {
width: 40%;
height: 100%;
padding: 0 7%;
margin: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: space-evenly;
-ms-flex-pack: space-evenly;
justify-content: space-evenly;
list-style: none;
}
.navbar-nav .nav-item {
text-align: center;
}
.navbar-nav .nav-item .item-link {
position: relative;
width: 100%;
padding: 15px 20px;
color: var(--white-smoke);
text-decoration: none;
border-radius: 5px;
border: 1px solid #0e0e0e00;
}
.navbar-nav .nav-item .item-link:hover {
background-color: var(--shadow);
border: 1px solid #4e4e4e4d;
}
.navbar-nav .c:hover #drop-down {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.navbar-nav .c:focus-within #drop-down {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.navbar-nav .c #drop-down {
position: absolute;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
display: none;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
top: 60px;
background-color: var(--white-smoke);
padding: 30px 0;
border-radius: 5px;
text-align: left;
-webkit-box-shadow: 0 0 10px var(--shadow);
box-shadow: 0 0 10px var(--shadow);
-webkit-transform: translateX(-10%);
transform: translateX(-10%);
}
.navbar-nav .c #drop-down .clinks {
display: block;
color: #000;
padding: 5px 0;
text-decoration: none;
padding: 10px 50px 10px 20px;
}
.navbar-nav .c #drop-down .clinks i {
padding: 0 2px;
}
.navbar-nav .c #drop-down .clinks:hover {
background-color: var(--shadow);
}
#media screen and (max-width: 1000px) {
.navbar #brand {
display: none;
}
.navbar .navbar-nav {
width: 100%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<title>DropDown Menu</title>
</head>
<body>
<nav class="navbar">
<ul class="navbar-nav">
<!-- Home -->
<li class="nav-item h">Home
</li>
<!-- Categories -->
<li class="nav-item c">
<a href="#" class="item-link">
<i class="fa fa-angle-down" aria-hidden="true"></i> Investieren</a>
<!-- Dropdown Menu -->
<div id="drop-down">
<a href="#" class="clinks"> <i class="fa fa-code" aria-hidden="true"></i> Web Development
</a>
<a href="#" class="clinks"> <i class="fa fa-android" aria-hidden="true"></i> Mobile Apps
</a>
<a href="#" class="clinks"> <i class="fa fa-adjust" aria-hidden="true"></i> UI / UX
</a>
<a href="#" class="clinks"> <i class="fa fa-database" aria-hidden="true"></i> Database
</a>
<a href="#" class="clinks"> <i class="fa fa-gamepad" aria-hidden="true"></i> Game Development
</a>
</div>
</li>
<!-- Prices -->
<li class="nav-item p">Prices
</li>
<!-- About -->
<li class="nav-item a">About
</li>
</ul>
</nav>
</body>
</html>
It's because you have the navbar set to a fixed position with a top of 20%.
.navbar {
position: fixed; //this will make sure the navbar always stays in its position
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
top: 20%; //this is what is causing the "space" above
width: 100%;
height: 70px;
background-color: black;
-webkit-box-shadow: 0 0 10px var(--shadow);
box-shadow: 0 0 10px var(--shadow);
color:white;
margin-top:2px;
}
You're telling the navbar to go down 20% of the page with the top:20%. If you don't want the space, just remove the top: 20% and you should be fine.
The issue is you have the navbar set to top: 20%;. You need to set it the fixed position to top 0%:
.navbar {
top: 0%;
left: 0%;
right: 0%;
}

How do I align icons in navbar

So basically I want to be able to align my icons in my navbar but they are staying on the left, the icons are meant to be on the same line and centered when the sidebar is opened.
As you can see they are staying on the left
Image:
https://i.stack.imgur.com/8n3WO.png
If you wanna see what i mean by having the icons align on same line and be centered, check Tom Walkers navbar below
https://iamtomwalker.com
Navbar code:
session_start();
?>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="./css/navbar.css?d=<?php echo time(); ?>">
<link rel="stylesheet" type="text/css" href="./css/style.css?d=<?php echo time(); ?>">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<nav class="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="material-icons">menu</i>
</span>
Test
<ul class="main-nav" id="js-menu">
<li>Home</li>
<li>Covers</li>
<li>Music</li>
<li>Newsletter</li>
<li style="display: inline-block;text-align: center; clear:left;"><i class="material-icons">menu</i> </li>
<li style="display: inline-block;text-align: center; clear:left;"><i class="material-icons">menu</i> </li>
<?php
if(isset($_SESSION['logged_in'])){
echo '<li>Account</li> ';
echo '<li>Manage</li> ';
echo '<li>Logout</li> ';
}
?>
</ul>
</nav>
<script>
let mainNav = document.getElementById("js-menu");
let navBarToggle = document.getElementById("js-navbar-toggle");
navBarToggle.addEventListener("click", function() {
mainNav.classList.toggle("active");
});
</script>
Navbar CSS
#import url('https://fonts.googleapis.com/css2?family=Fredericka+the+Great&display=swap');
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.navbar {
font-size: 18px;
background-color: #151515;
padding-bottom: 10px;
border-bottom: 1px solid white;
}
.main-nav {
list-style-type: none;
display: none;
clear: left;
}
.nav-links, .logo {
text-decoration: none;
font-family: 'Fredericka the Great', cursive;
color: rgba(255, 255, 255, 0.7);
}
.nav-links:hover{
text-decoration: underline;
}
.main-nav li {
text-align: center;
margin: 15px auto;
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
display: block;
}
#media screen and (min-width: 768px) {
.navbar {
display: flex;
justify-content: space-between;
padding-bottom: 0;
height: 70px;
align-items: center;
}
.main-nav {
display: flex;
margin-right: 30px;
flex-direction: row;
justify-content: flex-end;
}
.main-nav li {
margin: 0;
}
.nav-links {
margin-left: 40px;
}
.logo {
margin-top: 0;
}
.navbar-toggle {
display: none;
}
.logo:hover, .nav-links:hover {
color: rgba(255, 255, 255, 1);
}```
[1]: https://iamtomwalker.com
A few ways to do this, but most simply, add display: inline, and float: left to your li css
.main-nav li {
display: inline;
float: left;
margin: 15px auto;
}
Display inline will make the list items no longer block elements, and they will fall in place, side by side.
Floating will just put them all to either side of the parent.
You can set your spacing from here.
https://jsfiddle.net/ywk1cd5h/6/
I would look to wrap the icons that you want to be within a straight line in another flex box container.
<ul class="main-nav" id="js-menu">
<li>Home</li>
<li>Covers</li>
<li>Music</li>
<li>Newsletter</li>
<div class="icons">
<li style="text-align: center; "><i class="material-icons">menu</i> </li>
<li style="text-align: center;"><i class="material-icons">menu</i> </li>
</div>
</ul>
And then center the content. You can also adjust the margin: 15px auto as well.
.icons {
display: flex;
justify-content: center;
}
.main-nav {
display: flex;
margin-right: 30px;
flex-direction: row;
justify-content: flex-end;
}
.main-nav li {
text-align: center;
margin: 15px 0;
}

Logo CSS navbar keeps exploding

I realize that this question was asked before by different posters, but I tried a lot of suggested answers and none of them seemed to work.
When inputting my logo into the NavBar, it keeps expanding. However, the <li class="logo"> slot is reserved in the navbar, as the left class does leave room, but only as much as their designated 8% width not 40%.
ul.navbar {
width: 100%;
height: 50px;
line-height: 50px;
list-style-type: none;
padding: 0;
background-color: #5D6576;
opacity: 0.8;
border: none;
}
li.logo {
float: left;
width: 40%;
}
li.left {
float: left;
color: white;
width: 8%;
}
li.left a {
display: block;
color: white;
text-align: center;
text-decoration: none;
}
li a:hover {
background-color: #BC80BB;
transition: 1s;
}
li.right {
float: right;
width: 4%;
}
<ul class="navbar">
<li class="logo"><img src="static/logo.png" alt="Logo"></li>
<li class="left">Home</li>
<li class="left">*** Website</li>
<li class="right"><i class="fa fa-fw fa-envelope"></i></li>
<li class="right"><i class="fa fa-fw fa-phone"></i></li>
</ul>
Extremely expanding logo:
Showing the reserved spot:
Here i am sending you code as well as link. Please check it. If any changes then let me know.
https://jsfiddle.net/np6tzxyd/16/
.header-menu {
display: flex;
background-color: #5D6576;
opacity: 0.8;
width: 100%;
height: 50px;
line-height: 50px;
align-items: center;
justify-content: space-between;
}
.navbar-left,
.navbar-right {
display: flex;
list-style-type: none;
padding: 0;
border: none;
}
.navbar-left li,
.navbar-right li {
padding-right: 15px
}
.navbar-left li a:hover,
.navbar-right li a:hover {
color: #fff;
}
.logo {
display: block;
padding-right: 20px;
}
.logo-menu{
display: flex;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="header-menu">
<div class="logo-menu">
<a class="logo"><img src="static/logo.png" alt="Logo"></a>
<ul class="navbar-left">
<li>Home</li>
<li>*** Website</li>
</ul>
</div>
<ul class="navbar-right">
<li><i class="fa fa-fw fa-envelope"></i></li>
<li><i class="fa fa-fw fa-phone"></i></li>
</ul>
</div>
Following #Revti Shah answer to prevent jumping outside the nav you need to add this
overflow: hidden;
in your code
ul.navbar
or in her code
header-menu

Why does my navbar appear to be floating?

I want to make a fixed navbar at the bottom of the viewport with two sections. On the left, links for the rest of the site, and on the right, links to outside sources. I want to have everything both horizontally and vertically centered and to be responsive. For every solution I've tried, the height, alignment or size of the navbar is slightly off.
If I set the content div to 90% and the navbar div to 10%, then it "works" and things are aligned correctly, but I want the navbar to be slightly thinner.
As you can see with the border I styled the nav div with, its basically floating, and I have no idea why.
I've seen some similar questions, but a lot of the answers seem to point to outdated solutions using floats, etc.
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Montserrat', sans-serif;
}
.page {
height: 100%;
}
.main-content {
height: 90%;
max-width: 70%;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.main-left {
text-align: center;
padding: 20px;
}
.nav {
border: 1px solid blue;
height: 5%;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.nav-left {
display: flex;
width: 50%;
height: 100%;
justify-content: center;
font-size: 3vh;
line-height: 10vh;
}
.nav-right {
display: flex;
width: 50%;
height: 100%;
justify-content: center;
font-size: 3vh;
line-height: 10vh;
}
.nav ul {
padding: 0;
margin: 0;
display: inline-block;
}
.nav li {
display: inline-block;
text-align: center;
}
.nav a {
color: black;
}
.nav a:link {
text-decoration: none;
}
.nav a:visited {
text-decoration: none;
}
.nav a:hover {
text-decoration: none;
color: gray;
}
.nav a:active {
text-decoration: none;
}
img {
border-radius: 50%;
}
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<script src="https://use.fontawesome.com/383177a704.js"></script>
<title>Alex Wilson - Man, Web Designer, Legend</title>
</head>
<body>
<div class="page">
<div class="main-content">
<div class="main-left">
<img src="http://i.imgur.com/IMIKhWA.jpg"></img>
</div>
<div class="main-right">
<h1>About me</h1>
<p>These are words about how awesome I am. I'm pretty much the best. Scratch that, I am the best. Everything I say is right and everything I do is great. My friends love me and my enemies want to be me. People can't imagine any way I could possibly
be improved. I'm a shining example of humanity and more specifically, manhood. I'm the pinnacle of excellence. I piss glory and shit greatness. You mad? Get at me. Get rekt.</p>
</div>
</div>
<div class="nav">
<div class="nav-left">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Work
</li>
</ul>
</div>
<div class="nav-right">
<ul class="list-right">
<li><i class="fa fa-linkedin" aria-hidden="true"></i>
</li>
<li><i class="fa fa-github" aria-hidden="true"></i>
</li>
<li><i class="fa fa-twitter" aria-hidden="true"></i>
</li>
<li><i class="fa fa-facebook" aria-hidden="true"></i>
</li>
<li><i class="fa fa-envelope" aria-hidden="true"></i>
</li>
</ul>
</div>
</div>
</div>
</body>
Here's a CodePen.
So I did a few things to your code:
Made your page element a flexbox too:
.page {
height: 100%;
display: flex;
flex-direction: column;
}
And removed the heights for the main-content and nav, and the max-width for the main-content(better to set it in pixels according to content rather than percentages I guess).
For making the navbar slightly thinner perhaps you can reduce the line-height for the nav-left or nav-right.
Also added flex: 0 0 auto so that the the nav doesn't shrink too much when the height of the viewport is small (because line-height of nav is in viewport pixels).
See demo below:
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Montserrat', sans-serif;
}
.page {
height: 100%;
display: flex;
flex-direction: column;
}
.main-content {
/*height: 90%;*/
/*max-width: 70%;*/
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.main-left {
text-align: center;
padding: 20px;
}
.nav {
border: 1px solid blue;
/*height: 10%;*/
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex: 0 0 auto; /* addded */
}
.nav-left {
display: flex;
width: 50%;
height: 100%;
justify-content: center;
font-size: 3vh;
line-height: 5vh;
}
.nav-right {
display: flex;
width: 50%;
height: 100%;
justify-content: center;
font-size: 3vh;
line-height: 5vh;
}
.nav ul {
padding: 0;
margin: 0;
display: inline-block;
}
.nav li {
display: inline-block;
text-align: center;
}
.nav a {
color: black;
}
.nav a:link {
text-decoration: none;
}
.nav a:visited {
text-decoration: none;
}
.nav a:hover {
text-decoration: none;
color: gray;
}
.nav a:active {
text-decoration: none;
}
img {
border-radius: 50%;
}
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<script src="https://use.fontawesome.com/383177a704.js"></script>
<div class="page">
<div class="main-content">
<div class="main-left">
<img src="http://i.imgur.com/IMIKhWA.jpg"></img>
</div>
<div class="main-right">
<h1>About me</h1>
<p>These are words about how awesome I am. I'm pretty much the best. Scratch that, I am the best. Everything I say is right and everything I do is great. My friends love me and my enemies want to be me. People can't imagine any way I could possibly
be improved. I'm a shining example of humanity and more specifically, manhood. I'm the pinnacle of excellence. I piss glory and shit greatness. You mad? Get at me. Get rekt.</p>
</div>
</div>
<div class="nav">
<div class="nav-left">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Work
</li>
</ul>
</div>
<div class="nav-right">
<ul class="list-right">
<li><i class="fa fa-linkedin" aria-hidden="true"></i>
</li>
<li><i class="fa fa-github" aria-hidden="true"></i>
</li>
<li><i class="fa fa-twitter" aria-hidden="true"></i>
</li>
<li><i class="fa fa-facebook" aria-hidden="true"></i>
</li>
<li><i class="fa fa-envelope" aria-hidden="true"></i>
</li>
</ul>
</div>
</div>