I'm trying to implement a navigation system with a drop down menu. This menu will also have an extra menu that drops to the right. Without using lists.
I'm having difficulties positioning the right down menu. What I'm trying to do is have a menu pop out on the same height but at the right side of the hovered button.
How I wanted to do this was by using absolute position.
What I understand is that
position: absolute; refers to the first positioned parent.
In my case, i'm assuming:-
"navbar" -- Parent
"subnav" -- 1st Child
"subnav-content" -- 2nd child
"subnav-content-subnav" -- 3rd child
"subnavbtn2x" -- 4th child
.subnav-content2x{
position: absolute;
}
When I add the above code, from which class is the position being referenced?
My plan was to have the position from subnavbtn2x
referenced in positioning the right down menu.
Or perhaps someone has a better way of doing it?
HTML
<div class="navbar">
<div class="subnav">
<button class="subnavbtn">First Nav</button>
<div class="subnav-content">
Some page
Some page
Some page
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Second nav</button>
<div class="subnav-content">
<div class="subnav-content-subnav">
<button class="subnavbtn2x">Right first</button>
<div class="subnav-content2x">
Right 1
Right 2
</div>
</div>
<div class="subnav-content-subnav">
<button class="subnavbtn2x">Right Second</button>
<div class="subnav-content2x">
Right 3
Right 4
</div>
</div>
</div>
</div>
</div>
CSS
.navbar {
overflow: hidden;
}
.subnav {
overflow: hidden;
float: left;
}
.subnav-content {
display: none;
position: absolute;
background-color: #7E8185;
min-width: 160px;
z-index: 1;
}
.subnav-content a {
float: none;
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.subnav .subnavbtn {
font-size: 16px;
border: none;
outline: none;
color: black;
margin: 0;
}
.subnavbtn2x {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: -16px -16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.subnav-content2x {
display: none;
position: absolute;
background-color: #7E8185;
margin-left: 1px;
top: 1%;
left: 100%;
min-width: fit-content;
z-index: 1;
}
.subnav-content2x a {
float: left;
text-decoration: none;
display: block;
text-align: left;
}
.navbar a:hover,
.subnav:hover .subnavbtn {
background-color: #7E8185;
}
.subnav:hover .subnav-content {
display: block;
}
.subnav .subnav-content-subnav:hover .subnav-content2x {
display: block;
}
Expected result: https://imgur.com/zi4rrgX
current result: https://jsfiddle.net/RBee/cLsgpa5w/
Add
.subnav-content-subnav{
position: relative;
}
.navbar {
overflow: hidden;
}
.subnav {
overflow: hidden;
float: left;
}
.subnav-content {
display: none;
position: absolute;
background-color: #7E8185;
min-width: 160px;
z-index: 1;
}
.subnav-content a {
float: none;
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.subnav .subnavbtn {
font-size: 16px;
border: none;
outline: none;
color: black;
margin: 0;
}
.subnavbtn2x {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: -16px -16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.subnav-content2x {
display: none;
position: absolute;
background-color: #7E8185;
margin-left: 1px;
top: 1%;
left: 100%;
min-width: fit-content;
z-index: 1;
}
.subnav-content2x a {
float: left;
text-decoration: none;
display: block;
text-align: left;
}
.navbar a:hover,
.subnav:hover .subnavbtn {
background-color: #7E8185;
}
.subnav:hover .subnav-content {
display: block;
}
.subnav .subnav-content-subnav:hover .subnav-content2x {
display: block;
}
/* ===== Edit ===== */
.subnav-content-subnav{
position: relative;
}
<div class="navbar">
<div class="subnav">
<button class="subnavbtn">First Nav</button>
<div class="subnav-content">
Some page
Some page
Some page
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Second nav</button>
<div class="subnav-content">
<div class="subnav-content-subnav">
<button class="subnavbtn2x">Right first</button>
<div class="subnav-content2x">
Right 1
Right 2
</div>
</div>
<div class="subnav-content-subnav">
<button class="subnavbtn2x">Right Second</button>
<div class="subnav-content2x">
Right 3
Right 4
</div>
</div>
</div>
</div>
</div>
Live preview: https://jsfiddle.net/v41ubmn8/
add .subnav-content-subnav {position: relative;}
Related
i am curios on how i would get a logo above the Navbar
Like this:
I am not really sure how i can achieve this, i basically want the navbar to not be at the very top, but have the logo-top at the top of the site, then have the Navbar centered on the Logo, while the Logo is above the Navbar, so basically a part of the Navbar should be hidden behind it, and then align the buttons left and right of it
body {
margin: 0;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: grey;
}
.navbar a {
display: inline-block;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
display: inline-block;
}
.dropdown .dropbtn {
display: inline-block;
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;
}
.content {
padding: 16px;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 60px;
}
.logo {
width: 10% !important;
height: 10% !important;
position: absolute;
left: 50%;
margin-left: -50px !important; /* 50% of your logo width */
display: block;
}
<div class="navbar" align="center">
Home
News
<img src="https://via.placeholder.com/50" width="5%; height=5%; z-index: 10">
<div class="dropdown">
<button class="dropbtn">Server
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content" align="center">
Server 2
Server 1
</div>
</div>
Discord
</div>
You could use flex box model and play around with the negative margin on the logo (I use .middle-logo class in here as an example):
body {
margin: 0;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
background-color: grey;
display: flex;
align-items: center;
justify-content: center;
margin-top: 10px;
}
.navbar a {
display: inline-block;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
display: inline-block;
}
.dropdown .dropbtn {
display: inline-block;
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;
}
.content {
padding: 16px;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky+.content {
padding-top: 60px;
}
.logo {
width: 10% !important;
height: 10% !important;
position: absolute;
left: 50%;
margin-left: -50px !important;
/* 50% of your logo width */
display: block;
}
.middle-logo {
height: 66px;
margin-top: -10px;
margin-bottom: -10px;
display: inline-block;
width: 66px;
}
<div class="navbar" align="center">
Home
News
<img src="https://w7.pngwing.com/pngs/107/759/png-transparent-circle-white-circle-white-monochrome-black-thumbnail.png" width="5%; height=5%; z-index: 10" class="middle-logo">
<div class="dropdown">
<button class="dropbtn">Server
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content" align="center">
Server 2
Server 1
</div>
</div>
Discord
</div>
I used a random width/height here though, but the important part here is to use that negative margin, you could just adjust it according to your need
You can change the layer of your image/logo with z-index in css
I have navigation bar. I want to move the text 50px from left. I can do this?
.navigation {
width: 100%;
height:35px;
background-color: #f1b500; /*f2c255*/
margin-top: 4.4em;
}
.navigation a {
float: left;
display: block;
color: white;
text-align: center;
padding: 8px 25px;
text-decoration: none;
font-size: 100%;
}
.navigation .icon {
display: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 100%;
border: none;
outline: none;
color: white;
padding: 8px 25px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1b500;
min-width: 120px;
box-shadow: 0px 8px 16px 9px rbga(0,0,0,0.2)
z-index: 1;
}
.dropdown-content a {
float: none;
color: white;
padding: 8px 15px;
text-decoration: none;
display: block;
text-align: inherit;
}
.navigation a:hover, .dropdown:hover .dropbtn {
background-color: #34b0ff;
color: black;
}
.dropdown-content a:hover {
background-color: #34b0ff;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
The menu text is now all the way to the left. I would like to move it 50 pixels further to the right. Is the code wrong or do you just need to add something? I tried adding margin-left: 50px; but it does not work. I state that I am a beginner on programming.
<div class="navigation" id="Nav">
Home
<div class="dropdown">
<button class="dropbtn">Dropbutton
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link1
Link2
Link3
</div>
</div>
Test
Test
</div>
This is my html code. I forgot to post it
add padding-left:50px to .navigation. and everything will move to the right 50px
.navigation {
width: 100%;
height:35px;
background-color: #f1b500; /*f2c255*/
margin-top: 4.4em;
padding-left:50px;
}
.navigation a {
float: left;
display: block;
color: white;
text-align: center;
padding: 8px 25px;
text-decoration: none;
font-size: 100%;
}
.navigation .icon {
display: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 100%;
border: none;
outline: none;
color: white;
padding: 8px 25px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1b500;
min-width: 120px;
box-shadow: 0px 8px 16px 9px rbga(0,0,0,0.2)
z-index: 1;
}
.dropdown-content a {
float: none;
color: white;
padding: 8px 15px;
text-decoration: none;
display: block;
text-align: inherit;
}
.navigation a:hover, .dropdown:hover .dropbtn {
background-color: #34b0ff;
color: black;
}
.dropdown-content a:hover {
background-color: #34b0ff;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navigation" id="Nav">
Home
<div class="dropdown">
<button class="dropbtn">Dropbutton
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link1
Link2
Link3
</div>
</div>
Test
Test
</div>
yeah change your padding to 8px 25px 0px 50px
Either adding padding-left: 50px; or transform: translateY(50px);
My menu has logo to the left then links beside it, then a dropdown link to the right.. however the dropdown link on the end refuses to float right.
logo ---- link link link link ------------------dropdownlink
#main {
position: fixed;
width: 100%;
padding-top: 0px;
height: 60px;
font-size: 12px;
text-transform: uppercase;
background-color: #000;
z-index: 30;
}
#main a {
text-decoration: none;
}
.logo {
display: block;
margin-top: 10px;
height: 40px;
width: auto;
float: left;
}
.nav {
display: flex;
max-width: 1600px;
}
.right, .left{
display: inline-block;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: auto;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 22px 16px;
text-decoration: none;
float: left;
}
li a:hover {
background-color: #000;
}
.dropbtn {
background-color: #000;
margin-top: 10px;
color: #f0f0ee;
padding-top: 12px;
padding-bottom: 20px;
border: none;
cursor: pointer;
min-width: 100px;
text-transform: uppercase;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f0f0ee;
min-width: 185px;
right: 0px;
}
.dropdown-content a {
color: #000;
padding: 13px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #e8e8e7;
}
.dropdown:hover .dropdown-content {
display: block;
float: left;
}
.dropdown:hover .dropbtn {
background-color: #f0f0ee;
color: #000;
}
<header id="main">
<div class="container-fluid">
<div class="nav">
<img src="images/logo.png" class="logo">
<ul class="left">
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
<div class="right">
<div class="dropdown">
<button class="dropbtn">link <span class="caret"></span></button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
</header>
Add css class with right: 0 and position:absolute property
.right {
position: absolute;
right: 0;
}
#main {
position: fixed;
width: 100%;
padding-top: 0px;
height: 60px;
font-size: 12px;
text-transform: uppercase;
background-color: #000;
z-index: 30;
}
#main a {
text-decoration: none;
}
.logo {
display: block;
margin-top: 10px;
height: 40px;
width: auto;
float: left;
}
.right {
position: absolute;
right: 0;
}
.nav {
display: flex;
max-width: 1600px;
}
.right, .left{
display: inline-block;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: auto;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 22px 16px;
text-decoration: none;
float: left;
}
li a:hover {
background-color: #000;
}
.dropbtn {
background-color: #000;
margin-top: 10px;
color: #f0f0ee;
padding-top: 12px;
padding-bottom: 20px;
border: none;
cursor: pointer;
min-width: 100px;
text-transform: uppercase;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f0f0ee;
min-width: 185px;
right: 0px;
}
.dropdown-content a {
color: #000;
padding: 13px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #e8e8e7;
}
.dropdown:hover .dropdown-content {
display: block;
float: left;
}
.dropdown:hover .dropbtn {
background-color: #f0f0ee;
color: #000;
}
<header id="main">
<div class="container-fluid">
<div class="nav">
<img src="images/logo.png" class="logo">
<ul class="left">
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
<div class="right">
<div class="dropdown">
<button class="dropbtn">link <span class="caret"></span></button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
</header>
I've made a top bar that contains drop-down MENU button on the right side. But this drop-down content has exactly the same size (width) as my MENU button. Finally - my goal is to make this drop-down content as wide as the top bar is.
My HTML code looks like this:
<div id="top-bar">
<div class="dropdown">
<button class="dropbtn">MENU</button>
<div class="dropdown-content">
Link
Link
Link
</div>
</div>
</div>
And more important part - CSS:
#top-bar{
left: 0;
top: 0;
float: left;
width:100%;
height:40px;
background-color: black;
}
.dropbtn {
background-color: blue;
color: white;
height: 40px;
font-size: 12px;
border: none;
cursor: pointer;
}
.dropdown {
float: right;
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
float: left;
position: absolute;
background-color: #f9f9f9;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 10px 14px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
width: 100%;
float: left;
left: 0;
}
.dropdown:hover .dropbtn {
background-color: blue;
}
If you want to see how does it look like HERE is jsFiddle link.
Don't you have any idea how to solve my problem?
Just move position: relative from .dropdown to #top-bar.
By doing this, .dropdown-content will calculate width according to the nearest element with position: relative i.e #top-bar.
#top-bar{
position: relative;
height:40px;
float: left;
width: 100%;
background-color: black;
}
.dropbtn {
background-color: blue;
color: white;
height: 40px;
font-size: 12px;
border: none;
cursor: pointer;
}
.dropdown {
float: right;
}
.dropdown-content {
display: none;
left: 0;
top: 100%;
position: absolute;
background-color: #f9f9f9;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 10px 14px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: blue;
}
<div id="top-bar">
<div class="dropdown">
<button class="dropbtn">MENU</button>
<div class="dropdown-content">
Link
Link
Link
</div>
</div>
</div>
I think that's what you want
#top-bar{
left: 0;
top: 0;
float: left;
width:100%;
height:40px;
background-color: black;
}
.dropbtn {
display: block;
float: right;
background-color: blue;
color: white;
height: 40px;
font-size: 12px;
border: none;
cursor: pointer;
}
.dropdown {
width: 100%;
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
float: left;
background-color: #f9f9f9;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 10px 14px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
width: 100%;
float: left;
left: 0;
}
.dropdown:hover .dropbtn {
background-color: blue;
}
<div id="top-bar">
<div class="dropdown">
<button class="dropbtn">MENU</button>
<div class="dropdown-content">
Link
Link
Link
</div>
</div>
</div>
https://jsfiddle.net/69uts0dr/3/
I have a nav i made that works just as i want.. my only issue is the button drop down is to display to the right of the first 2 links how ever it displays first and forces the links to display last.
it displays the links after the drop down so instead of
logo --------------------- Home- News- Dropdown
it displays
logo --------------------- Dropdown- Home- News
drop down should be on the end
CODE
#siteHeader {
padding-top: 22px;
height: 90px;
background-color: black;
}
.logo {
display: block;
height: 45px;
width: auto;
float: left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: auto;
display: block;
float: right;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
float: left;
}
li a:hover {
background-color: #000;
}
.dropbtn {
background-color: #000;
color: white;
padding-top: 16px;
padding-bottom: 33px;
font-size: 12px;
text-transform: uppercase;
border: none;
cursor: pointer;
min-width: 100px;
}
.dropdown {
position: relative;
display: inline-block;
float: right;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #434343;
min-width: 185px;
right: 0;
text-transform: uppercase;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
font-size: 12px;
}
.dropdown-content a:hover {
background-color: #000000
}
.dropdown:hover .dropdown-content {
display: block;
float: left;
}
.dropdown:hover .dropbtn {
background-color: #434343;
color: white;
}
<div id="siteHeader">
<div class="container-fluid">
<img src="../content/images/official_logo_white.png" class="logo">
<ul>
<li>Home
</li>
<li>News
</li>
</ul>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
just switch them
#siteHeader {
padding-top: 22px;
height: 90px;
background-color: black;
}
.logo {
display: block;
height: 45px;
width: auto;
float: left;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: auto;
display: block;
float: right;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
float: left;
}
li a:hover {
background-color: #000;
}
.dropbtn {
background-color: #000;
color: white;
padding-top: 16px;
padding-bottom: 33px;
font-size: 12px;
text-transform: uppercase;
border: none;
cursor: pointer;
min-width: 100px;
}
.dropdown {
position: relative;
display: inline-block;
float: right;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #434343;
min-width: 185px;
right: 0;
text-transform: uppercase;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
font-size: 12px;
}
.dropdown-content a:hover {background-color: #000000}
.dropdown:hover .dropdown-content {
display: block;
float: left;
}
.dropdown:hover .dropbtn {
background-color: #434343;
color: white;
}
<div id="siteHeader">
<div class="container-fluid">
<img src="../content/images/official_logo_white.png" class="logo">
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<ul>
<li>Home</li>
<li>News</li>
</ul>
</div>
</div>
If I were you I would remove those floats and simplify by using flexbox
#siteHeader {
padding-top: 22px;
height: 90px;
background-color: black;
}
.container-fluid {
display: flex
}
.nav {
flex: 1;
display: flex;
justify-content: flex-end
}
.logo {
flex: 0 50px
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: auto;
display: block;
}
li {
display: inline-block
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #000;
}
.dropbtn {
background-color: #000;
color: white;
padding-top: 16px;
padding-bottom: 33px;
font-size: 12px;
text-transform: uppercase;
border: none;
cursor: pointer;
min-width: 100px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #434343;
right: 0;
text-transform: uppercase;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
font-size: 12px;
}
.dropdown-content a:hover {
background-color: #000
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #434343;
color: white;
}
<div id="siteHeader">
<div class="container-fluid">
<img src="../content/images/official_logo_white.png" class="logo">
<div class="nav">
<ul>
<li>Home
</li>
<li>News
</li>
</ul>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
In <ul> I have changed its css property display: block to display: inline-block and for <div class="dropdown"> I have also made it display: inline-block as by default div is block level of element so both can fit in same line and I have wrap both <div> and <ul> to one <div> that will put them on right side by using float: right
see answer in below snippet.
#siteHeader {
padding-top: 22px;
height: 90px;
background-color: black;
}
.logo {
display: block;
height: 45px;
width: auto;
float: left;
}
.nav {
float: right;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: auto;
display: inline-block;
float: left;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
float: left;
}
.dropdown {
display: inline-block;
float: left;
}
<div id="siteHeader">
<div class="container-fluid">
<img src="../content/images/official_logo_white.png" class="logo">
<div class="nav">
<ul>
<li>Home</li>
<li>News</li>
</ul>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>