Align everything vertically inside navbar - html

I am trying to center everything vertically inside the container of the navbar, called (header-area) such that everything is inline. At the moment the img, left navigation and right navigation are all aligned differently in the container.
An alternative solution is welcome, too.
/*-----Global Styles-----*/
html {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
border: 0;
}
body {
font-family: 'HKGroteskRegular';
}
*, *:before, *:after {
box-sizing: inherit;
}
/*--------------Header-Navigation--------------*/
.header-area{
position: relative;
top: 0;
left: 0;
width: 100%;
z-index: 9999;
padding: 9px 97px 26px 98px;
height: 105px;
margin: 0 auto;
}
.logo-wrap{
float: left;
width: auto;
}
.main-logo{
width: 212px;
float: left;
}
.main-logo a{
float: left;
}
.main-logo img{
width: 100%;
}
.main-nav{
float: left;
margin: 0;
}
.main-nav ul li{
display: inline-block;
padding: 0 25px;
position: relative;
}
.main-nav ul li:after{
position: absolute;
top: 50%;
right: 0;
width: 24px;
height: 2px;
}
.main-nav ul li:last-child{
padding-right: 21px;
}
.main-nav ul li:last-child:after{
display: none;
}
.main-nav ul li a{
color: #0c225f;
padding: 2.5px 0;
text-decoration: none;
font-family: 'HKGroteskBold';
font-size: 19px;
}
.header-right{
float: right;
width: auto;
display: flex;
align-items: center;
}
.header-right a{
vertical-align: middle;
display: flex;
align-items: center;
text-decoration: none;
}
.phone {
padding: 0 20px 0 10px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/hk-grotesk" type="text/css"/>
<link rel="stylesheet" href="css/untitled.css">
<title>Document</title>
</head>
<body>
<div class="mainwrap">
<!--Header-->
<header class="header-area">
<div class="logo-wrap">
<div class="main-logo">
<img src="Assets/logo.png" alt="pd-logo">
</div>
</div>
<div class="header-left">
<nav class="main-nav">
<ul id="menu-main-menu" class="menu">
<li>Who We Are</li>
<li>Products</li>
<li>Stories</li>
<li>Career</li>
<li>Contact</li>
</ul>
</nav>
<div class="header-right">
Give us a Call<img class="phone" src="Assets/Phone.svg">0123456789
</div>
</div>
</header>
</div>
</body>
</html>

Add the following styles to menu-main-menu ul
display: flex;
align-items: center;

Your .logo-wrap value has a float value of left, so you'll want to make sure the other children have a similar quality to appear inline. To do this, add a float: left; styling with your header-left class. For this example, I shrunk the font size and padding to demonstrate the new float value and padding.
I highly recommend researching 'flex' to align your navigation. With flex, you can treat each nav item (logo, links, buttons) as child, and align them vertically with justify-content: center;. This way you won't have to worry about floats or padding issues.
html {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
border: 0;
}
body {
font-family: 'HKGroteskRegular';
}
*, *:before, *:after {
box-sizing: inherit;
}
/*--------------Header-Navigation--------------*/
.header-area{
position: relative;
top: 0;
left: 0;
width: 100%;
z-index: 9999;
padding: 9px 97px 26px 98px;
height: 105px;
margin: 0 auto;
}
.header-left {
float: left; /* added */
padding: 24px 0; /* updated */
}
.logo-wrap{
float: left;
width: auto;
}
.main-logo{
width: 48px; /* updated */
float: left;
padding: 24px 0; /* added */
}
.main-logo a{
float: left;
}
.main-logo img{
width: 100%;
}
.main-nav{
float: left;
margin: 0;
}
.main-nav ul {
padding: 0; /* added */
margin: 0; /* added */
}
.main-nav ul li{
display: inline-block;
padding: 0 6px;
position: relative;
}
.main-nav ul li:after{
position: absolute;
top: 50%;
right: 0;
width: 24px;
height: 2px;
}
.main-nav ul li:last-child{
padding-right: 21px;
}
.main-nav ul li:last-child:after{
display: none;
}
.main-nav ul li a{
color: #0c225f;
padding: 2.5px 0;
text-decoration: none;
font-family: 'HKGroteskBold';
font-size: 8px;
}
.header-right {
float: right;
width: auto;
display: flex;
align-items: center;
}
.header-right a {
vertical-align: middle;
display: flex;
align-items: center;
text-decoration: none;
font-size: 8px; /* added */
}
.phone {
padding: 0 20px 0 10px;
}
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/hk-grotesk" type="text/css"/>
<link rel="stylesheet" href="css/untitled.css">
<title>Document</title>
</head>
<body>
<div class="mainwrap">
<!--Header-->
<header class="header-area">
<div class="logo-wrap">
<div class="main-logo">
<img src="Assets/logo.png" alt="pd-logo">
</div>
</div>
<div class="header-left">
<nav class="main-nav">
<ul id="menu-main-menu" class="menu">
<li>Who We Are</li>
<li>Products</li>
<li>Stories</li>
<li>Career</li>
<li>Contact</li>
</ul>
</nav>
<div class="header-right">
Give us a Call<img class="phone" src="Assets/Phone.svg">0123456789
</div>
</div>
</header>
</div>
</body>
</html>

you achieve this using display: flex;align-items:center;. in ..header-area.
please run snippet in full page mode
/*-----Global Styles-----*/
html {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
border: 0;
}
body {
font-family: 'HKGroteskRegular';
}
*, *:before, *:after {
box-sizing: inherit;
}
/*--------------Header-Navigation--------------*/
.header-area{
position: relative;
width: 100%;
z-index: 9999;
padding: 9px 10px 26px 10px;
height: 105px;
margin: 0 auto;
display: flex;
align-items:center;
}
.main-logo img{
width: 100%;
}
.menu {
padding-left: 0;
display: flex;
}
.main-nav{
margin: 0;
}
.main-nav ul li{
display: inline-block;
padding: 0 25px;
position: relative;
}
.main-nav ul li:after{
position: absolute;
top: 50%;
right: 0;
width: 24px;
height: 2px;
}
.main-nav ul li:last-child{
padding-right: 21px;
}
.main-nav ul li:last-child:after{
display: none;
}
.main-nav ul li a{
color: #0c225f;
padding: 2.5px 0;
text-decoration: none;
font-family: 'HKGroteskBold';
font-size: 12px;
}
.header-right{
width: auto;
display: flex;
align-items: center;
margin-left:auto;
font-size: 12px;
}
.header-right a{
vertical-align: middle;
text-decoration: none;
}
.phone {
padding: 0 20px 0 10px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/hk-grotesk" type="text/css"/>
<link rel="stylesheet" href="css/untitled.css">
<title>Document</title>
</head>
<body>
<div class="mainwrap">
<!--Header-->
<header class="header-area">
<div class="logo-wrap">
<div class="main-logo">
<img src="Assets/logo.png" alt="pd-logo">
</div>
</div>
<div class="header-left">
<nav class="main-nav">
<ul id="menu-main-menu" class="menu">
<li>link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</nav>
</div>
<div class="header-right">
Give us a Call<img class="phone" src="Assets/Phone.svg">0123456789
</div>
</header>
</div>
</body>
</html>
I changed your font-size for demonstration purpose

Related

How do I get my navbar menu to line up with logo?

Here is the fiddle: https://jsfiddle.net/gnsho1br/2/
There were similar questions that suggests to set display to inline-block but I have done that. My container is col-1. I also tried to give my logo class of float: left but then the menu is off-center (maybe the left margin starts at the end of the logo???).
Use display: flex instead. If you want items to be centered, try align-items: center, justify-items: center. Refer to Flexbox for more info.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
li,
a,
button {
font-family: "Elliot-Sans", sans-serif;
font-weight: 300;
font-size: 14px;
color: #777777;
text-decoration: none;
}
#wrapper {
margin: 0 15px;
padding: 15px 0;
position: relative;
}
.row {
max-width: 65%;
margin: 0 auto;
padding: 75px 0;
position: relative;
}
.col-1 {
width: 100%;
padding: 20px;
display: flex;
}
#header {
height: 71px !important;
overflow: visible;
z-index: 9999;
width: 100%;
position: absolute !important;
}
#header .row {
padding: 0;
}
#header ul {
text-align: center;
}
.logo {
width: 150px;
height: auto;
cursor: pointer;
margin-right: auto;
background-color: inherit;
display: inline-block;
vertical-align: middle;
}
#topNavBar {
list-style: none;
margin: 0;
background-color: #ffffff;
}
ul{
display: flex;
}
#topNavBar li {
display: inline-block;
padding: 0px 20px;
background-color: inherit;
vertical-align: middle;
}
#topNavBar li a {
transition: all 0.2s ease 0s;
font-weight: 400;
text-transform: uppercase;
}
#topNavBar li a:hover {
color: #04ad9e;
text-decoration: none;
padding-bottom: 4px;
border-bottom: 3px solid #04ad9e;
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
rel="stylesheet"
/> -->
<link
href="https://fonts.googleapis.com/css2?family=Rajdhani:wght#300;400&display=swap"
rel="stylesheet"
/>
<link
href="https://unpkg.com/tailwindcss#^1.0/dist/tailwind.min.css"
rel="stylesheet"
/>
<link href="style.css" rel="stylesheet" />
<title>Title</title>
</head>
<body>
<div id="wrapper">
<header id="heroImage">
<div id="header" class="navCollapse">
<div class="row clearfix">
<div class="col-1">
<div class="logo">
<img class="logo" src="image.png" alt="logo" />
</div>
<nav id="topNavBar">
<ul>
<li>Home</li>
<li>About</li>
<li>Read</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</div>
</header>
</div>

Position a drop-down menu on top of an hr

I hope you guys can help me with the next thing. I've made the top of a website. When you hover the navigation, a dropdown menu will show. unfortunately this dropdown is positioned under a hr. How can i fix it to get this positioned on top of an hr? The hr is required element, so I can't remove it. Here is the example of the problem
Html code:
#import url('https://fonts.googleapis.com/css?family=Lato:300i,400,400i,700,900');
html {
box-sizing: border-box;
}
body {
font: 15px 'Lato', sans-serif;
margin: 0;
padding: 0;
}
.container {
margin: auto;
max-width: 1024px;
width: 100%;
overflow: hidden;
}
hr {
border-color: #b9b9b9;
position: absolute;
width: 100%;
margin-top: -55.5%;
}
header {
width: 80%;
margin-left: 10%;
}
header img {
width: 15%;
height: auto;
}
img {
width: 100%;
height: auto;
margin: -1% 0 0.5% 0;
}
h1 {
display: none;
}
nav {
float: right;
padding: 2% 0 5% 0;
}
li {
display: inline-block;
position: relative;
padding: 10px 0px 0px 0px;
margin-left: 10px;
}
header a {
text-decoration: none;
text-transform: uppercase;
font-size: 12px;
color: black;
font-weight: 400;
}
ul ul {
position: absolute;
left: 0;
top: 100%;
display: none;
padding: 1% 0;
}
li:hover ul {
display: block;
background-color: gainsboro;
}
ul ul a {
color: white;
}
.selected {
border-bottom: 2px solid #49997b;
padding-bottom: 0.5%;
}
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vakantie op de Dominicaanse Republiek</title>
<link rel="stylesheet" href="CSS/vakantie.css" type="text/css">
<link rel="stylesheet" href="CSS/normalize.css" type="text/css">
</head>
<body>
<div class="container">
<header>
<h1>Vakantie op de Dominicaanse republiek</h1>
<nav>
<ul>
<li class="selected">Home</li>
<li>Bezienswaardigheden</li>
<li>Over de Dominicaanse
<ul>
<li>Reisdocumenten</li>
<li>Inentingen</li>
<li>Feestdagen</li>
<li>Geld en koers</li>
</ul>
</li>
<li>Recreatie</li>
<li>Contact</li>
</ul>
</nav>
</header>
<img src="Afbeeldingen/Dominicaanse_header.jpg" alt="dominicaanse">
<hr>
</div>
</body>
</html>
You can set the menu's z-index higher than the hr and it should appear on top instead of behind it. I can't see the image to tell if this works or not but it should.
hr {
border-color: #b9b9b9;
position: absolute;
width: 100%;
margin-top: -55.5%;
z-index: 1;
}
.container {
margin: auto;
max-width: 1024px;
width: 100%;
overflow: hidden;
z-index: 2;
}

Alignment of Header and Nav Bar

I am just getting back to working with websites, and cannot for the life of me center this navigation bar. I have floated the header over to the left, and feel like I have tried every possibly property, but it just will not center. Any help would be very appreciated.
Not centered NavBar:
.container {
margin: 0 auto;
background-color: #fff;
}
.header-heading {
float: left;
padding-top: 8px;
padding-left: 5px;
color: #ddd;
font-size: 30px;
}
.nav-bar {
background: #000;
padding: 0;
width: 100%;
}
.nav {
margin: auto;
padding: 0;
list-style: none;
text-align: center;
width: 100%;
}
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Web Report Demo</title>
<styles></styles>
<link rel="stylesheet" href="ed.css">
</head>
<body>
<div class="container">
<h1 class="header-heading">Web Reporting Demo</h1>
<div class="nav-bar">
<ul class="nav">
<li>Daily Master</li>
<li>Route Progress</li>
<li>UL Move Query</li>
<li>Stock Query</li>
</ul>
</div>
</div>
</body>
This should work
.container {
margin: 0 auto;
background-color: #000;
position:relative;
width: 100%;
height: 40px;
}
.header-heading {
position: absolute;
top:-20px;
left:5px;
color: #ddd;
font-size: 30px;
}
.nav-bar {
padding-top: 5px;
}
.nav {
margin: auto;
padding: 5px;
list-style: none;
text-align: center;
width: 100%;
}
.nav li {
display: inline;
padding: 5px;
}
.nav li a {
text-decoration: none;
color: #fff;
}
You will need to do some changes as you work in your responsive design.
Try giving the .container text-align: center.

How to center image inside of an li?

I have this html below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="event.css">
</head>
<body>
<header class="header-container">
<div class="navigation">
<div class="navigation-content">
<h1 class="heading">
Test
</h1>
<ul class="heading-list">
<li>Sell<img src="money.png"></li>
<li>Buy<span><img src="tickets.png"></li>
<li>Sign in<span><img src="locked.png"></li>
</ul>
</div>
</div>
</header>
</body>
</html>
And this css below:
body {
font-family: "Helvetica Neue",Helvetica,Roboto,Arial,"Lucida Grande",sans-serif;
margin: 0;
padding: 0;
font-size: 14px;
background-color: #F6F8F9;
}
.header-container {
background-color: #260354;
width: 100%;
position: relative;
}
.navigation {
width: 100%;
max-width: 1280px;
margin: 0 auto;
}
.navigation-content {
padding: 15px 30px;
border-bottom: none;
}
.heading {
color: white;
margin: 0;
padding: 0;
display: inline-block;
}
.heading-list {
float: right;
list-style: none;
overflow: hidden;
}
.heading-list li {
color: white;
float: left;
padding-right: 30px;
}
.heading-list li img {
color: white;
width: 24px;
height: 24px;
margin-left: 10px;
text-align: center;
}
In the navigation list on the top right (ul) I want to center those images with the li text in my css. I tried putting text-align: center; on the .heading-list li img but it is not centering the image. Is there something else I have to do?
You can use flexbox, as I used in this example
body {
font-family: "Helvetica Neue",Helvetica,Roboto,Arial,"Lucida Grande",sans-serif;
margin: 0;
padding: 0;
font-size: 14px;
background-color: #F6F8F9;
}
.header-container {
background-color: #260354;
width: 100%;
position: relative;
}
.navigation {
width: 100%;
max-width: 1280px;
margin: 0 auto;
}
.navigation-content {
padding: 15px 30px;
border-bottom: none;
}
.heading {
color: white;
margin: 0;
padding: 0;
display: inline-block;
}
.heading-list {
float: right;
list-style: none;
overflow: hidden;
}
.heading-list li {
color: white;
float: left;
padding-right: 30px;
display: flex;
align-items: center;
}
.heading-list li img {
color: white;
width: 24px;
height: 24px;
margin-left: 10px;
text-align: center;
}
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="event.css">
</head>
<body>
<header class="header-container">
<div class="navigation">
<div class="navigation-content">
<h1 class="heading">
Test
</h1>
<ul class="heading-list">
<li>
<span>Sell</span>
<img src="https://pbs.twimg.com/profile_images/3038657495/3d2f325c92060a35e7ac8c697c57d8d4.jpeg">
</li>
<li>
<span>Buy</span>
<img src="https://pbs.twimg.com/profile_images/630664501776527361/nIK2xTUE.jpg">
</li>
<li>
<span>Sign in</span>
<img src="http://www.dailyworldfacts.com/wp-content/uploads/2011/06/facts-about-cat-fallen-cat.jpg">
</li>
</ul>
</div>
</div>
</header>
</body>
</html>
So an image by default has a display type of inline-block. To enable it to be centered, include the following in your images css.
display: block;
margin-left: auto;
margin-right: auto

Nav isn't at the top of the page?

I'm trying to have my nav at the top right of the page but it displays like 100px down from the top. I have no clue what's causing this, I tried altering the padding and margin of other things in the header but I cant solve it. Any help ?
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CT Designs | Home</title>
<!-- Stylesheets-->
<link rel="stylesheet" type="text/css" href="css/index.css">
<!-- Fonts-->
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
<header>
<div class="container">
<div id="branding">
<h1> CT Designs </h1>
</div>
<div id="menu">
<svg height="40px" style="enable-background:new 0 0 32 32;" version="1.1" viewBox="0 0 32 32" width="40px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path class="fill" d="M4,10h24c1.104,0,2-0.896,2-2s-0.896-2-2-2H4C2.896,6,2,6.896,2,8S2.896,10,4,10z M28,14H4c-1.104,0-2,0.896-2,2 s0.896,2,2,2h24c1.104,0,2-0.896,2-2S29.104,14,28,14z M28,22H4c-1.104,0-2,0.896-2,2s0.896,2,2,2h24c1.104,0,2-0.896,2-2 S29.104,22,28,22z"/></svg>
</div>
<nav>
<ul>
<li>Home</li>
<li>About Me</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
<script src="jquery-3.1.1.min" href="main.js"></script>
</body>
</html>
CSS:
body {
margin: 0;
padding: 0;
}
.container {
min-width: 80%;
float: center;
}
ul {
padding: 0;
margin: 0;
}
header {
position: fixed;
width: 100%;
height: 100%;
background-image: url("../resources/img/header.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
header .container #branding h1 {
display: block;
position: absolute;
top: 45%;
left: 50%;
transform: translateX(-50%);
font-size: 70px;
text-transform: uppercase;
font-weight: 400;
margin: 0;
padding: 0;
font-family: Roboto;
color: #fff;
margin-top: -0.5em;
padding: 30px;
border: solid 3px #fff;
}
header .container #menu {
margin: 10px;
padding: 0;
width: 100px;
}
header .container #menu svg {
cursor: pointer;
margin: 0;
padding: 0;
}
header .container #menu svg path.fill {
fill: white;
}
header .container nav ul {
float: right;
margin-bottom: 40px;
}
header .container ul li {
display: inline-block;
text-decoration: none;
color: white;
font-size: 20px;
font-family: Roboto;
padding-right: 20px;
}
You have set your header .container nav ul to float right, which is under your div#menuand that's where the space is coming: the space is caused by the svg element you have, which your 'hamburger' menu.
Here is one solution:
#menu {
float: left;
}
header .container nav ul {
float: right;
margin-top: 20px;
}