I have a menu bar that I am trying to float right, I also have a logo that I would like to keep to the left.
I have been able to get the menu to float to the right and keep the logo on the right however the menu is being pushed down in is not in line with the logo.
How do I get the menu in line with the logo?
If I put float left on the logo it leaves a weird gap at the top and messes up the layout.
Here is my code
.navbar-collapse ul a {
font-family: "Barlow", sans-serif;
color: white;
text-decoration: none;
vertical-align: top;
}
.navbar-collapse ul a:hover {
background-color: white;
color: #23303e;
border-radius: 50px;
text-transform: uppercase;
font-weight: 900;
font-family: "Fraunces", serif;
padding: 10px 30px 10px;
}
}
.navbar-collapse ul {
padding: 0;
margin: 0;
float: right;
display: flex;
}
.navbar-collapse li {
display: inline;
float: left;
}
.logo {
width: 20%;
margin: 0 auto;
padding: 7.5px 10px 7.5px 0;
}
}
<nav>
<div class="container-fluid">
<a class="nav-brand" href="#page-top"><img src="images/logo.svg" class="logo" alt="Sunnyside Logo"></a>
<button class="navbar-toggle" type="button">
<img src="images/icon-hamburger.svg" class="hamburger" alt="hamburger">
</button>
<div class="navbar-collapse">
<ul>
<li class="nav-link text-center">About</li>
<li class="nav-link text-center">Services</li>
<li class="nav-link text-center">Projects</li>
<li class="nav-link text-center">Contact</li>
</ul>
</div>
</div>
</nav>
You need to put display: flex for .container-fluid that helps all your menu items on the same line as logo. To align right for menu items, you should put margin-left: auto for .navbar-collapse
Here is the full code
.navbar-collapse ul a {
font-family: "Barlow", sans-serif;
color: white;
text-decoration: none;
vertical-align: top;
}
.container-fluid {
display: flex;
}
.navbar-collapse {
margin-left: auto;
}
.navbar-collapse ul a:hover {
background-color: white;
color: #23303e;
border-radius: 50px;
text-transform: uppercase;
font-weight: 900;
font-family: "Fraunces", serif;
padding: 10px 30px 10px;
}
}
.navbar-collapse ul {
padding: 0;
margin: 0;
float: right;
display: flex;
}
.navbar-collapse li {
display: inline;
float: left;
}
.logo {
width: 20%;
margin: 0 auto;
padding: 7.5px 10px 7.5px 0;
}
}
<nav>
<div class="container-fluid">
<a class="nav-brand" href="#page-top"><img src="images/logo.svg" class="logo" alt="Sunnyside Logo"></a>
<button class="navbar-toggle" type="button">
<img src="images/icon-hamburger.svg" class="hamburger" alt="hamburger">
</button>
<div class="navbar-collapse">
<ul>
<li class="nav-link text-center">About</li>
<li class="nav-link text-center">Services</li>
<li class="nav-link text-center">Projects</li>
<li class="nav-link text-center">Contact</li>
</ul>
</div>
</div>
</nav>
Related
I want to make a navbar and between my links I have a selectable space. How can I make it non selectable?
This is the code:
.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.navhome {
font-weight: 600;
color: rgba(255, 255, 255, 0.664);
}
.navlinks {
font-size: 15px;
}
.navlinks a {
font-weight: 570;
margin-top: -40px;
text-align: center;
padding: 15px 10px;
text-decoration: none;
float: right;
color: rgba(255, 255, 255, 0.863);
margin-left: -4px
}
.navlinks>.navlinks a:not(:last-child) {
margin-left: -10px;
}
<nav class="navbar">
<a class="navhome" id="noselect">home</a>
<div class="navlinks">
<li>testlink</li>
</div>
<div class="navlinks">
<li>testlink1</li>
</div>
</nav>
How can I make the space between links non selectable in html?
A simpler way to do this could be as follows.
Put all the links that you have in a div or header tag and make the display of the element flex so that everything inside the div or header tag get positioned in a line. I've used align-items CSS property to centre the links vertically as well. Then for each link declare a left margin or a right margin so that they don't stick to each other.
Note that I have initially set the default margin and padding of all the elements to 0px.
#import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
* {
margin: 0px;
padding: 0px;
}
header {
display: flex;
align-items: center;
background-color: #0D0D0D;
padding: 10px;
}
.Header-Link {
font-family: "Poppins";
text-decoration: none;
color: #FFFFFF;
margin-right: 25px;
}
<html>
<body>
<header>
<a class="Header-Link" href="https://www.stackoverflow.com" target="_blank">Home</a>
<a class="Header-Link" href="https://www.stackoverflow.com" target="_blank">Test Link 1</a>
<a class="Header-Link" href="https://www.stackoverflow.com" target="_blank">Test Link 2</a>
</header>
</body>
</html>
Try this I made few changes in CSS classes and the format of code and syntax and exclude unnecessary CSS and make it the right way and the spaces between the links are non selectable by simply giving .nav-item a margin-right: 10px;
.navbar{
background-color: #303030;
}
.navbar-nav{
list-style: none;
display: inline-flex;
}
.nav-item{
margin-right: 10px;
}
.nav-item a{
text-decoration: none;
font-weight: normal;
text-align: center;
float: right;
color: #ffffffdc;
font-size: 15px;
font-family: Arial, Helvetica, sans-serif;
}
.nav-item a.active{
font-weight: bold;
color: #daa520;
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="#" active>Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">testlink</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">testlink1</a>
</li>
</ul>
</nav>
I have a hover dropdown menu and the image wont in the main button else when it fits the dropdown looks weird. When i hover over the user12345 button the image is on the left side just before the hover shadow. I have attached the codes including the dropdown nav codes in the snippet below. Thank you so much for your help
HTML:
body {
font-family: arial;
margin: 0;
padding: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
}
.dropdown {
margin: 0 auto;
}
nav {
height: 77px;
text-decoration:none;
}
ul {
padding: 0;
margin: 0 auto;
float: right;
margin-right:30px;
}
ul li {
position: relative;
list-style: none;
display: inline-block;
background: #343a40;
}
ul li a {
display: block;
padding: 0 15px;
color: #D3D3D3;
text-decoration: none;
line-height: 60px;
font-size: 20px;
}
ul li a:hover {
background: #3b4044;
text-decoration:none;
opacity: 1 !important;
}
ul ul {
position: absolute;
top: 62px;
display: none;
background: #343a40;
}
li:hover ul {
display: block;
text-decoration:none;
background: #343a40 !important;
}
h5 {
margin-bottom: .5rem;
font-family: inherit;
line-height: 1.2;
}
b{
font-weight: 542;
}
ul li:hover > ul {
display: block;
}
ul ul li {
width:150px;
float: none;
display: list-item;
position: relative;
}
.user {
margin-left: 20px; }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="dropdown ">
<nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
<a id="name" href="index.html">
<img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top" alt="">
</a>
<h5 style="font-size: 22px" class="ml-2 text-info mt-2"><b>Gobble</b></h5>
<ul>
<img src="images/noprofile.png" class="user " style="width:48px;height:48px">
<li> User12345
<ul>
<li>Profile</li>
</ul>
</nav> </div>
Can you check below solution, hope it will resolve your issue.
body {
font-family: arial;
margin: 0;
padding: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
}
.dropdown {
margin: 0 auto;
}
nav {
height: 77px;
text-decoration:none;
}
.dropdown ul {
margin:0;
padding: 0;
margin: 0 auto;
float: right;
margin-right:30px;
}
ul li {
position: relative;
list-style: none;
display: inline-block;
background: #343a40;
}
ul li a {
display: inline-block;
padding: 0 15px;
color: #D3D3D3;
text-decoration: none;
line-height: 60px;
font-size: 20px;
}
ul li a img {
margin-right: 20px;
}
ul li a:hover {
background: #3b4044;
text-decoration:none;
opacity: 1 !important;
}
ul ul {
position: absolute;
top: 62px;
display: none;
background: #343a40;
}
li:hover ul {
display: block;
text-decoration:none;
background: #343a40 !important;
}
h5 {
margin-bottom: .5rem;
font-family: inherit;
line-height: 1.2;
}
b{
font-weight: 542;
}
ul li:hover > ul {
display: block;
}
ul ul li {
width:150px;
float: none;
display: list-item;
position: relative;
}
.user {
margin-left: 20px; }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="dropdown">
<nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
<a id="name" href="index.html">
<img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top" alt="">
</a>
<h5 style="font-size: 22px" class="ml-2 text-info mt-2"><b>Gobble</b></h5>
<ul>
<li>
<img src="images/noprofile.png" class="user" style="width:48px;height:48px">User12345
<ul>
<li>Profile</li>
</ul>
</li>
</ul>
</nav>
</div>
I hope I understand correctly what you mean.
this code can help you. you must put img tag in your a tag.
<div class="dropdown ">
<nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
<a id="name" href="index.html">
<img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top" alt=""> </a>
<h5 style="font-size: 22px" class="ml-2 text-info mt-2"><b>Gobble</b></h5>
<ul>
<li><a href="#"><img src="images/noprofile.png" class="user "
style="width:48px;height:48px;"> User12345</a></li>
<ul>
<li><a href="#" class="nav-item">Profile</a
</li>
</ul>
</ul>
</nav>
</div>
you can set position:relative style for your img tag to put it correctly beside a tag.
also you can use flexbox, it's a very good tool for put elements next to each other.
you can learn about it in w3schools or css-tricks:
https://www.w3schools.com/css/css3_flexbox.asp
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I am trying to move things around in the header navbar under #media trying to make my site responsive. I'm tinkering with a bunch of stuff but I've hit a wall.
I'm trying to space out my header navbar links which currently are not spaced apart, and I'm also trying to move my subscription bar to the far right inside the navbar.
Since I have been tinkering with stuff I probably have excess code in places it should not be, if so please let me know so I can understand how moving items functions and what I should avoid in the future.
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
height: 100px;
display: flex;
padding: 10px 0 30px 10px;
}
.header-logo img {
height: 100px;
padding: 10px 0px 10px 10px;
float: left;
}
header nav ul {
display: block;
margin: 50px 0 0 auto;
padding: 0 0 0 10px;
width: fit-content;
}
header nav ul li {
display: inline-block;
padding: 0 5px;
}
header nav ul li a {
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.home-link {
float: right;
padding: 0 0 0 0px;
}
.sub {
display: none;
background-color: rgb(70, 149, 223);
margin-left: 5%;
height: auto;
list-style: none;
}
/* HAMBURGER MENU */
.nav div {
height: 4px;
background-color: rgb(20, 15, 15);
margin: 5px 0;
border-radius: 25px;
transition: 0.3s;
}
.nav {
width: 30;
display: block;
float: right;
margin: 1em 0 0 1em;
padding-right: 0px;
}
.one {
width: 30px;
}
.two {
width: 20px;
}
.three {
width: 25px;
}
.nav:hover div {
width: 30px;
}
#hamburger {
display: none;
list-style: none;
}
.hamburger-toggle {
float: right;
padding: 25px 0px 0px 125px;
}
ul li a:hover {
color: rgb(255, 255, 255);
}
/* Desktop Media */
#media only screen and (min-width: 1000px) {
header .header-logo {
float: left;
padding: 10px 10px 10px 10px;
height: auto;
width: 220px;
display: table;
}
header nav ul {
margin: 0 auto;
padding-right: 50px;
}
header nav ul li {
padding: 0 0 0 50px;
}
header nav ul li a {
line-height: 150px;
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
padding: 0 0 0 50px;
}
header .sub {
display: block;
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
line-height: 50px;
border: 2px solid #111;
float: right;
padding: 2px 20px;
}
.sub {
margin-left: auto;
height: auto;
position: relative;
z-index: 1000;
width: fit-content;
height: 40px;
background-color: rgb(70, 149, 223);
}
.index-banner {
width: 100%;
height: calc(100vh - 100px);
max-width: 1080px;
margin-right: auto;
margin-left: auto;
background-image: url('img/road_trip.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.index-banner h1 {
display: block;
padding: 120px 0 0px 120px;
font-family: 'Karma', serif;
font-size: 60px;
font-weight: 900;
color: #fff;
text-shadow: 4px 4px 16px #111;
}
.verticial-center {
margin: 0 auto;
display: table-cell;
vertical-align: middle;
padding: 120px 0 0 0;
}
.nav {
display: none;
}
#hamburger {
display: flex;
line-height: 150px;
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.hamburger-toggle {
display: none;
}
}
/*INDEX*/
.index-banner {
width: 100%;
height: calc(100vh - 100px);
background-image: url('img/road_trip.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.index-banner h1 {
padding-top: 30px;
font-family: 'Karma', serif;
font-size: 60px;
font-weight: 900;
line-height: 70px;
color: #fff;
text-align: center;
text-shadow: 4px 4px 16px #111;
}
.verticial-center {
margin: 0 auto;
display: table-cell;
vertical-align: middle;
}
/* HERO SECTION */
.hero-section {
font-family: 'Sorts Mill Goudy', serif;
font-size: 24px;
color: #111;
width: 100%;
max-width: 1080px;
/* or whatever width you want */
margin-right: auto;
margin-left: auto;
}
.hero-section {
font-family: 'Karma', serif;
font-size: 40px;
color: #111;
text-align: center;
padding: 25px;
}
.hero-paragraph {
margin: 0 auto;
max-width: 100%;
font-family: 'Sorts Mill Goudy', serif;
font-size: 24px;
color: #111;
text-align: center;
padding: 25px;
}
/* RESPONSIVNESS */
#media only screen and (min-width: 1000px) {
.wrapper {
width: 100%;
margin: 0 auto;
}
.index-banner {
height: 500px;
}
.hero-paragraph {
width: 100%;
margin: 0 auto;
}
.hero-section {
width: 100%;
margin: 0 auto;
}
}
/* BLOG PAGE */
.body-wrapper {
width: 100%;
max-width: 1080px;
/* or whatever width you want */
margin-right: auto;
margin-left: auto;
padding-top: 50px;
}
.blog-title {
font-family: 'Sorts Mill Goudy', serif;
font-size: 60px;
color: #111;
text-align: center;
display: block;
}
.blog-title div {
font-family: 'Karma', serif;
font-size: 40px;
color: #111;
padding: 60px;
width: 50%;
text-align: left;
}
.blog-title div h1 {
font-family: 'Karma', serif;
font-size: 40px;
color: #111;
text-align: center;
}
/* FOOTER */
footer {
width: calc(100% - 80px);
padding: 40px 40px;
margin-top: 20px;
background-color: #111;
overflow: hidden;
}
footer ul {
width: fit-content;
float: left;
padding-left: 20px;
}
footer ul li {
display: block;
list-style: none;
}
footer ul li a {
font-family: 'Sorts Mill Goudy', serif;
font-size: 18px;
color: #fff;
line-height: 40px;
}
.footer-sm {
width: 50px;
float: right;
}
.footer {
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #fff;
text-align: center;
margin: 170px 0 0 0;
}
.footer-sm img {
width: 100%;
margin-bottom: 10px;
display: block;
}
/* FOOTER RESPONESIVNESS */
#media only screen and (min-width: 1000px) {
footer ul li a {
font-family: 'Sorts Mill Goudy', serif;
font-size: 18px;
color: #fff;
line-height: 40px;
}
}
<body>
<header>
<div class="header-logo">
<img src="https://milestonehackers.com/img/Milestonehackers.jpg" alt="Milestonehackers logo">
</div>
<nav div class="home-link">
<ul>
<li>Home</li>
</ul>
</nav>
<nav>
<div class="hamburger-toggle">
<ul>
<a href="#" class="nav">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
<div id="hamburger">
<li>Podcast</li>
<li>Newsletter</li>
<li>Blog</li>
<li>Contact</li>
</div>
<div class="sub">
<li>Subscribe</li>
</div>
</a>
</ul>
</nav>
</header>
<main>
<section class="index-banner">
<div class="verticial-center">
<h1>The Milestone Hackers Podcast</h1>
</div>
</section>
<div class="wrapper">
<section class="hero-section">
<h2>What Can you Expect From our Podcast</h2>
<p class="hero-paragraph">A host (meee, Paolo) interviewing various types of entrepreneurs or founders both technical and non-technical. Each entrepreneur has their own unique story that resulted in learning or experiencing something that can benefit our audience who may
want to go down the entrepreneurial path!</p>
</section>
</div>
</main>
<div class="wrapper">
<footer>
<ul>
<li>Home</li>
<li>Podcast</li>
<li>Newsletter</li>
<li>Blog</li>
<li>Contact</li>
</ul>
<div class="footer-sm">
<a href="https://twitter.com/Milestonehacker">
<img src="img/twitter.png" alt="twiiter icon">
<a href="https://open.spotify.com/show/2ZiIxv5Mr83seTtNsg3LD9">
<img src="img/spotify.png" alt="spotify icon">
<img src="img/rss.png" alt="rss icon">
</a>
</div>
<p class="footer">Copyright © 2019; All Rights Reserved</p>
</footer>
Don't have a 3000x3000 px image that is about 100px when displaying. You're logo should be about 20kb at most for that size, not 742 kb.
Don't use float (or absolute), unless you're certain of what you're doing. Floats messes up all the divs that displays blocks. For example, you needed to set a height on your header because the logo was floating.
Start sketching out your design, and put everything in rectangles. You don't need that many elements just to display your header.
If you think your CSS is cluttered. Remove everything and start again, preferably from #3 above.
I added CSS variables. It's always good to have a margin that you keep for all distances. margin-half could be added as well.
:root {
--margin: 10px;
--margin-double: 20px;
}
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
display: flex;
align-items: center;
padding: var(--margin-double);
box-sizing: border-box; /* take padding into account for width */
}
header > .header-logo > a {
display: flex; /* to remove weird spacing behavior in Firefox */
}
header > .header-logo img {
height: 100px;
padding-right: var(--margin);
}
header > nav {
flex: 1 1 auto; /* Take up any free space within <header> */
display: flex;
flex-wrap: wrap;
height: 100%;
}
#media (min-width: 700px) {
header > nav {
justify-content: center;
}
}
header > nav > a {
margin-right: var(--margin);
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
line-height: 24px;
}
header > nav > a::before {
width: 100%;
height: 1px;
}
header > a.sub {
height: 20px;
padding: var(--margin);
align-self: end; /* I didn't know where you wanted the button */
background-color: rgb(70, 149, 223);
color: #fff;
}
<body>
<header>
<div class="header-logo">
<img src="https://milestonehackers.com/img/Milestonehackers.jpg" alt="Milestonehackers logo">
</div>
<nav>
Home
Podcast
Newsletter
Blog
Contact
</nav>
<a class="sub" href="subscribe.html">Subscribe</a>
</header>
</body>
Best practice to use bootstrap for responsive purpose as it provides n number of components and does have lot's of utility classes so you don't need to write your own CSS most of the places
Check out this link for details on utility classes
here
Here is the simple example by using bootstrap.
HTML:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
https://codepen.io/pgurav/pen/abbaOwW
I am trying to create a website and I need a multi level submenu.
I am facing 2 problems at the moment:
I dont know how to position the sub sub menu properly. It should appear next to the sub menu on the same height as the previous menu item and list downwards.
I don't know how to set that the sub sub menu only expands if I hover the corresponding sub menu item.
The code I am using is attached below.
I would appreciate if only the css is changed because the website runs with a programme that creates the html
The code is here: https://jsfiddle.net/TheBB23/Luxrakzq/
body {
margin: 0;
padding: 0;
background: #ccc;
color: #00782E;
font-family: Arial, Helvetica, sans-serif;
}
/* Header Leiste */
.nav{
width: 100%;
height: 70px;
background: #00782E;
position: fixed;
z-index: 2;
}
/* Hintergrund für Obermenüpunkte */
.nav ul {
width: 60%;
height: 70px;
list-style: none;
background: none;
text-align: center;
padding: 0;
margin-top: 0px;
margin-left: 25%;
margin-right: 15%;
position: fixed;
}
/* Position Menüoberpunkte */
.nav li {
line-height: 20px;
display: inline-block;
}
/* Style Menüoberpunkte */
.nav a{
text-decoration: none;
color: white;
width: auto;
display: block;
padding-top: 25px;
padding-right: 10px;
padding-left: 10px;
padding-bottom: 5px;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
.menulist {
display: none;
}
dropdown-content ul {
display: none;
}
/* Untermenü bei Hovern anzeigen*/
.dropdown:hover .menulist.menulist{
display: block;
margin-left: 0;
text-align: left;
width: 200px;
height: auto;
padding-top: 6px;
padding-bottom: 6px;
list-style: none;
margin-right: 0;
position: fixed;
background: white;
}
.menulist .menulist {
background-color: red !important;
width: 280px !important;
}
.dropdown:hover .dropdown-content ul ul {
display: none;
}
.menulist ul:hover .dropdown-content ul ul {
display: block !important;
}
/* Untermenüpunkte erster Ordnung Style*/
.menulist a {
color: #00782E;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
line-height: 12px;
font-weight: 500;
width: 150px;
padding-left: 16px;
padding-top: 10px;
padding-bottom: 10px;
text-decoration: none;
display: block;
text-align: left;
}
.menulist .menulist a {
font-size: 15px;
padding-top: 6px,
padding-bottom: 6px;
margin-right: 0px;
padding-right: 0px;
padding-left: 6px;
}
/* Abstand Untermenütext 1 zum Kasten */
.menulevel1 {
margin-left: 6px;
}
/* Untermenüpunkte 2. Ordnung Style */
.dropdown-menu a {
color: #00782E;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 12px;
font-weight: 500;
width: 150px;
padding-left: 16px;
padding-top: 1px;
padding-bottom: 1px;
text-decoration: none;
display: block;
text-align: left;
}
li a:hover, .dropdown:hover .dropbtn {
color: lightgrey !important;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class ="nav">
<ul>
<li class="dropdown">
Animals
<div class = "dropdown-content">
<ul class="menulist">
<li class="menulevel1">
<a class=" " href="lion">Lion</a>
</li>
<li class="menulevel1">
<a class=" " href="cat">cat</a>
</li>
<li class="menulevel1">
<a class=" " href="monkey">monkey</a>
</li>
<li class="menulevel1">
<a class=" " href="cow">cow</a>
</li>
<li class="menulevel1">
<a class=" " href="sheep">sheep</a>
</li>
<li class="menulevel1">
<a class=" " href="rat">rat</a>
</li>
</ul>
</div>
</li>
<li class="dropdown">
names
<div class = "dropdown-content">
<ul class="menulist">
<li class="menulevel1">
<a class=" " href="Pete">Pete</a>
</li>
<li class="menulevel1">
<a class=" " href="Finley">Finley</a>
</li>
<li class="menulevel1">
<a class=" " href="#">Jordan <span class="Jordan"></span></a>
<ul class="menulist">
<li class="menulevel2">
<a class=" " href="calvin">Calvin</a>
<li class="menulevel2">
<a class=" " href="harry">harry</a>
</li>
</ul>
</li>
<li class="menulevel1">
<a class=" " href="george">george</a>
</li>
</ul>
</div>
</li>
</ul>
</body>
</html>
Thank you for your help
I've been going around the web trying to find an answer to how to center my navbar but none of the solution worked.
The code below will show what I have so far with both HTML and CSS.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}
header #smcontent {
float: left;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</header>
This is how it looks like right now:
I have also noticed that in CSS, when I did "float: center;" it had no difference with when I did "float: left;". But when I did "float: right;" it would shift to the right.
ul {
margin: 0 auto;
text-align: center;
}
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin: 0 auto;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</div>
</header>
</body>
</html>
I have removed the below css from your code
header #smcontent {
float: left;
}
and added margin: 0 auto; text-align: center; to the ul
Try absolute position with float none, left 50% and a left translate of 50% to center your nav bar perfectly.
CSS: add
header .newCenter {
float: none;
position: absolute;
left: 50%;
transform: translate(-50%, 0);
}
HTML: add
<nav class="newCenter">
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
Float only applies to left and right. I added display: grid and justify-content: center to your header. I removed float: left; in header #smcontent.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
display: grid; //or flex
justify-content: center;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
display: inline;
padding: 0 20px;
}
header nav {
margin: 10px auto 0;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin: 0 auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</header>
To align text horizontally center use text-align:center. In your to align nav bar content center just add text-align:center to header nav
header nav {
margin-left: auto;
text-align:center;
margin-right: auto;
margin-top: 10px;
}
In below code snippet I have added some images for demonstration purpose.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
text-align:center;
margin-right: auto;
margin-top: 10px;
}
header #smcontent {
float: left;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="https://image.shutterstock.com/image-photo/kiev-ukraine-may-26-2015twitter-260nw-281505518.jpg">
</a>
<a href="https://facebook.com/">
<img src="https://image.shutterstock.com/image-photo/kiev-ukraine-april-27-2015-260nw-278925056.jpg">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</div>
</header>