Having Issues Making A Navigation Bar in Header - html

I am trying to make a Navigation Bar for the top of my page
.header {
width: 100%;
background-color: #2C2F33;
border-bottom: 2.5px #FF9F00 solid;
font-size: 15px;
}
#logo img {
float: left;
margin: 0;
padding: 20px;
width: 187.5px;
height: 63.75px;
}
.navbar {
display: flex;
justify-content: space-between;
}
.navbar,
li {
display: inline;
padding: 0 22.5px 0 22.5px;
}
.navbar,
li,
a {
text-decoration: none;
list-style-type: none;
}
.navbar,
li,
a:hover {
color: #FF9F00;
text-decoration: none;
list-style-type: none;
}
#dollarydoos,
#dsh {
color: #FF9F00;
}
#dosh {
color: #FFFFFF;
}
<div class="header">
<div id="logo">
<img src="./img/logo.png"></img>
</div>
<div class="navbar">
<div id="leftnavbar">
<ul>
<li><span id="dollarydoos">Dollarydoos:</span> <span id="dosh">1.00000000</span> <span id="dsh">DSH</span></li>
</ul>
</div>
<div id="rightnavbar">
<ul>
<li>Button1</li>
<li>Button2</li>
<li>Button3</li>
<li>Button4</li>
</ul>
</div>
</div>
</div>
I cant get the buttons and the dollardoos to have a small box that surrounds it (inside) and to align to the center of the logo and get listed in line in the center.
Like this:
How can I do this as I am not too experienced in HTML/CSS. I am a newbie trying to build his own site.

I made a flexbox of the header and removed display:inline for the navbar
.header {
width: 100%;
background-color: #2C2F33;
border-bottom: 2.5px #FF9F00 solid;
font-size: 15px;
display: flex;
align-items: center;
}
#logo img {
margin: 0;
padding: 20px;
width: 187.5px;
height: 63.75px;
}
.navbar {
display: flex;
justify-content: space-between;
margin-left: auto;
}
li {
display: inline;
padding: 0 22.5px 0 22.5px;
}
.navbar,
li,
a {
text-decoration: none;
list-style-type: none;
}
.navbar,
li,
a:hover {
color: #FF9F00;
text-decoration: none;
list-style-type: none;
}
#dollarydoos,
#dsh {
color: #FF9F00;
}
#dosh {
color: #FFFFFF;
}
<div class="header">
<div id="logo">
<img src="http://placehold.it/200x100">
</div>
<div class="navbar">
<div id="leftnavbar">
<ul>
<li><span id="dollarydoos">Dollarydoos:</span> <span id="dosh">1.00000000</span> <span id="dsh">DSH</span></li>
</ul>
</div>
<div id="rightnavbar">
<ul>
<li>Button1</li>
<li>Button2</li>
<li>Button3</li>
<li>Button4</li>
</ul>
</div>
</div>
</div>

Related

Drop-down menu is not working for some reason

My dropdown effect is not working what am I doing wrong. I have tried by putting display to none and using the :hover but nothing works.
As soon as I hover over the Menu, .drp-btn:hover .menu-content-container doesn't work.
<div class="nav-container">
<div class="drp-btn"> Menu </div>
<div class="menu-content-container">
<ul class="menu-content">
<li>Home</li>
<li>About</li>
<li>Booking</li>
</ul>
</div>
</div>
.nav-container {
margin-top: 2px;
display: flex;
flex-direction: column;
}
.menu-content-container {
border: 5px solid red;
}
.drp-btn {
margin-left: 60vw;
border: 2px solid red;
font-size: 20px;
}
.drp-btn:hover .menu-content-container {
display: flex;
background-color: red;
color: white;
}
.menu-content-container {
display: none;
}
.nav-container ul li {
margin-left: 2%;
list-style-type: none;
}
.nav-container a {
font-size: 20px;
text-decoration: none;
}
<div class="nav-container">
<div class="drp-btn"> Menu
<div class="menu-content-container">
<ul class="menu-content">
<li>Home</li>
<li>About</li>
<li>Booking</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
wrap the code drp-btn div
You need to wrap your menu-content-container into the drp-btn div to make that work:
.nav-container {
margin-top: 2px;
display: flex;
flex-direction: column;
}
.menu-content-container {
border: 5px solid red;
}
.drp-btn {
margin-left: 60vw;
border: 2px solid red;
font-size: 20px;
}
.drp-btn:hover .menu-content-container {
display: flex;
background-color: red;
color: white;
}
.menu-content-container {
display: none;
}
.nav-container ul li {
margin-left: 2%;
list-style-type: none;
}
.nav-container a {
font-size: 20px;
text-decoration: none;
}
<div class="nav-container">
<div class="drp-btn"> Menu
<div class="menu-content-container">
<ul class="menu-content">
<li>Home</li>
<li>About</li>
<li>Booking</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>

How do I center an unordered list? [duplicate]

This question already has answers here:
How to center an unordered list?
(8 answers)
How can I center <ul> <li> into a div?
(16 answers)
Closed 2 years ago.
I have a list and css.
However the ul goes to the left. I have tried many things but it either stays inline and floats to the left or it goes to the center as I want it to, but then it's not inline, they stack on one another..how can I have both an centered ordered list and inline?
.navbar {
display: table;
margin: 0 auto;
width: 100%;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
}
.navbar ul li {
display: inline-block;
}
li a {
display: block;
color: black;
text-align: center;
padding: 12px 16px;
font-size: 25px;
text-decoration: none;
}
<div class="navbar">
<ul>
<li>The Stock</li>
<li>
<a> <img style="height: 50px; width: 50px" src="img/logo.svg" alt="logotype" /> </a>
</li>
<li>The Stock</li>
</ul>
</div>
To center the navbar ul add text-align: center;
.navbar {
display: table;
margin: 0 auto;
width: 100%;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
text-align: center;
}
.navbar ul li {
display: inline-block;
}
li a {
display: block;
color: black;
text-align: center;
padding: 12px 16px;
font-size: 25px;
text-decoration: none;
}
<div class="navbar">
<ul>
<li>The Stock</li>
<li>
<a> <img style="height: 50px; width: 50px" src="img/logo.svg" alt="logotype" /> </a>
</li>
<li>The Stock</li>
</ul>
</div>
All you need is "text-align:center;" on your .navbar ul like below:
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
text-align: center;
}
<li> runs as a text element because of your css .navbar ul li { display: inline-block; }. therefor you can center it with text-align. In this case just add: .navbar { text-align: center; }
.navbar {
margin: 0 auto;
width: 100%;
text-align: center;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
}
.navbar ul li {
display: inline-block;
}
li a {
display: block;
color: black;
text-align: center;
padding: 12px 16px;
font-size: 25px;
text-decoration: none;
}
<div class="navbar">
<ul>
<li>The Stock</li>
<li>
<a> <img style="height: 50px; width: 50px" src="img/logo.svg" alt="logotype" /> </a>
</li>
<li>The Stock</li>
</ul>
</div>
Just use display: flex; justify-content: center; for either <ul> tag or navbar div container.
.navbar {
display: table;
margin: 0 auto;
width: 100%;
}
.navbar ul {
display: flex;
justify-content: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
}
.navbar ul li {
display: inline-block;
}
li a {
display: block;
color: black;
text-align: center;
padding: 12px 16px;
font-size: 25px;
text-decoration: none;
}
<div class="navbar">
<ul>
<li>The Stock</li>
<li>
<a> <img style="height: 50px; width: 50px" src="img/logo.svg" alt="logotype" /> </a>
</li>
<li>The Stock</li>
</ul>
</div>
Just change your .navbar class like this
.navbar {
display: flex;
justify-content: center;
}

How to vertically center text in a List containing an image

I'm starting in CSS and I can't figure out if it is possible to vertically center a text in an unordered list when it contains an Image.
I want to place a logo in my navbar ul and center the text but it sticks to the bottom of the Ul.
Heres the code and what I want:
Fiddle
Image showing what I want
HTML:
<body>
<header>
<nav id="navbar">
<ul>
<li><b><img class="logo" src="https://i28.servimg.com/u/f28/09/04/03/75/a_2_li10.png" alt="HOME"></b></li>
<li><b>MORE</b></li>
<li><b>SERVICES</b></li>
<li><b>BLOG</b></li>
<li><b>SHOP</b></li>
</ul>
</nav>
</header>
</body>
body {
background-color: #294F6D;
margin: 0;
}
#navbar ul {
margin: 0;
list-style: none;
background-color: #303E73;
text-align: center;
}
#navbar li {
display: inline-block;
background-color: #A13647;
padding: 20px 50px
}
.logo {
width: 100px;
}
All you need is vertical-align: middle;.
You can just add it to your CSS here:
#navbar li {
display: inline-block;
background-color: #A13647;
padding: 20px 50px;
vertical-align: middle;
}
Here's a working example:
body {
background-color: #294F6D;
margin: 0;
}
#navbar ul {
margin: 0;
list-style: none;
background-color: #303E73;
text-align: center;
}
#navbar li {
display: inline-block;
background-color: #A13647;
padding: 20px 50px;
vertical-align: middle;
}
.logo {
width: 100px;
}
<header>
<nav id="navbar">
<ul>
<li><b><img class="logo" src="https://i28.servimg.com/u/f28/09/04/03/75/a_2_li10.png" alt="HOME"></b></li>
<li><b>MORE</b></li>
<li><b>SERVICES</b></li>
<li><b>BLOG</b></li>
<li><b>SHOP</b></li>
</ul>
</nav>
</header>
display: flex is your friend here:
body {
background-color: #294F6D;
margin: 0;
}
#navbar ul {
align-items: center;
display: flex;
margin: 0;
list-style: none;
background-color: #303E73;
text-align: center;
}
#navbar li {
background-color: #A13647;
padding: 20px 50px
}
a {
text-decoration: none;
color:white;
}
a:hover {
text-decoration: underline;
}
.logo {
width: 100px;
}
<header>
<nav id="navbar">
<ul>
<li><b><img class="logo" src="https://i28.servimg.com/u/f28/09/04/03/75/a_2_li10.png" alt="HOME"></b></li>
<li><b>MORE</b></li>
<li><b>SERVICES</b></li>
<li><b>BLOG</b></li>
<li><b>SHOP</b></li>
</ul>
</nav>
</header>
Check out Flexbox on caniuse, as it still has a few edge-case issues in Internet Explorer. This example should work fine though.
body {
background-color: #294F6D;
margin: 0;
}
#navbar ul {
margin: 0;
list-style: none;
background-color: #303E73;
/* text-align: center; */
display: flex;
justify-content: center;
align-items: center;
}
#navbar li {
display: inline-block;
background-color: #A13647;
padding: 20px 50px;
}
#navbar li a {
text-decoration: none;
color: #000000;
}
.logo {
width: 100px;
}
<body>
<header>
<nav id="navbar">
<ul>
<li><b><img class="logo" src="https://i28.servimg.com/u/f28/09/04/03/75/a_2_li10.png" alt="HOME"></b></li>
<li><b>MORE</b></li>
<li><b>SERVICES</b></li>
<li><b>BLOG</b></li>
<li><b>SHOP</b></li>
</ul>
</nav>
</header>
</body>

Vertically Center Various Text in Header?

This can probably be fixed insanely easy but I'm just having such a hard time at doing it.
So, I want to make both my name and the navigation bar in the header appear at the center vertically. My current code only makes my name be centered, since it is bold and the font-size is bigger.
This is the code:
HTML:
<div id="header">
<ul>
<div id="header-wrapper">
<div class="header-name">
<li>
<a href="/index.html">
<span class="first"><strong>First</strong></span>
<span class="last"><strong> Last</strong></span>
</a>
</li>
</div>
<div class="header-nav">
<li>
Contact</li>
<li>
Portfolio</li>
<li>
About
</li>
<li>
Home
</li>
</div>
</div>
</ul>
CSS:
#header-wrapper {
width: 960px;
margin: 0 auto;
position: relative;
}
#header ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: orange;
box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.2);
}
#header .header-name li {
float: left;
}
#header .header-nav li {
float: right;
vertical-align: middle;
}
#header li a {
font-size: 15px;
display: block;
color: #FFF;
text-align: center;
padding: 20px 16px;
text-decoration: none;
}
#header .header-name li a {
font-size: 22px;
}
#header ul li a .first {
color: #ccc;
}
#header a {
vertical-align: middle;
}
Your HTML is invalid. A ul needs to have an li as direct children. Instead, you have divs as direct children with nested li's
That said, add display: flex; align-items: center; justify-content: space-between; to #header-wrapper to center those elements vertically.
#header-wrapper {
width: 960px;
margin: 0 auto;
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
}
#header ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: orange;
box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.2);
}
#header .header-name li {
float: left;
}
#header .header-nav li {
float: right;
vertical-align: middle;
}
#header li a {
font-size: 15px;
display: block;
color: #FFF;
text-align: center;
padding: 20px 16px;
text-decoration: none;
}
#header .header-name li a {
font-size: 22px;
}
#header ul li a .first {
color: #ccc;
}
#header a {
vertical-align: middle;
}
<div id="header">
<ul> <div id="header-wrapper">
<div class="header-name">
<li>
<a href="/index.html">
<span class="first"><strong>First</strong></span>
<span class="last"><strong> Last</strong></span>
</a>
</li>
</div>
<div class="header-nav">
<li>
Contact</li>
<li>
Portfolio</li>
<li>
About
</li>
<li>
Home
</li>
</div>
</div>
</ul>

Centering a ul stretch full width div

I want to get this menu bar to appear on the full width of the container/div (horizontal). With equal amount of margin in between the menu items, which are lis. I want this to work for every viewport.
The thing is margin: 0 auto; doesn't work. What should I do instead?
.button-row {
background-color: #fcfcfc;
position: relative;
height: 70px;
width: 100%;
float: left;
overflow: hidden;
position: relative;
}
.button-row ul {
clear: left;
float: left;
list-style: none;
margin: 0;
padding: 0;
position: relative;
left: 50%;
text-align: center;
}
.button-row ul li {
display: block;
float: left;
list-style: none;
margin: 0;
padding: 0;
position: relative;
right: 50%;
}
.button-row ul li a {
display: block;
margin: 0 0 0 1px;
padding: 3px 10px;
text-decoration: none;
line-height: 1.3em;
}
<div class="container-fluid">
<div class="row">
<div class="button-row">
<ul>
<li><a>Additional information</a>
</li>
<li><a>Current exchange rates</a>
</li>
<li><a>ATMs and institutions</a>
</li>
<li><a>Protection</a>
</li>
<li><a>Files to download</a>
</li>
</ul>
</div>
</div>
</div>
Full width of the container/div (horizontal). with equal amount of (margin) in between the li's, for every viewport as you wish.
You can try with flexbox like this, if that's what you want:
.button-row {
background-color: #fcfcfc;
height: 70px;
width: 100%;
}
.button-row ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: space-between;
}
.button-row ul li {
display: block;
list-style: none;
margin: 0;
padding: 0;
width: 20%;
text-align: center;
}
.button-row ul li a {
display: block;
margin: 0 0 0 1px;
padding: 3px 10px;
text-decoration: none;
line-height: 1.3em;
}
<div class="container-fluid">
<div class="row">
<div class="button-row">
<ul>
<li><a>Additional information</a>
</li>
<li><a>Current exchange rates</a>
</li>
<li><a>ATMs and institutions</a>
</li>
<li><a>Protection</a>
</li>
<li><a>Files to download</a>
</li>
</ul>
</div>
</div>
</div>
.button-row{
width: 100%;
}
.button-row a{
display: inline-block;
width: calc(100% / 5);
float: left;
text-align: center;
}
<div class="container-fluid">
<div class="row">
<div class="button-row">
<a>Additional information</a>
<a>Current exchange rates</a>
<a>ATMs and institutions</a>
<a>Protection</a>
<a>Files to download</a>
</div>
</div>
</div>
Without ul li and fully responsive.
Here my simple code of navigation bar
#navi
{
width:100%;
}
center{
background-color: #333;
height:7%;
}
.ulnav {
float:right;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
margin-right:350px;
}
.ulnav li {
float: left;
border-right:1px solid blue;
border-left:1px solid red;
}
.ulnav li:last-child {
border-right: none;
}
.ulnav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.ulnav li a:hover:not(.active) {
color: #ccff33;
background-color: #111;
}
.active {
background-color: #ccff33;
}
<center><ul class="ulnav">
<li><a class="active">Additional information</a>
</li>
<li><a>Current exchange rates</a>
</li>
<li><a>ATMs and institutions</a>
</li>
<li><a>Protection</a>
</li>
<li><a>Files to download</a>
</li>
</ul></center>