I have a problem, I need to do, two navigation and one logo on left side. What I need you can see on image below
I need to do effectively and responsively, when the browser shrinks, gaps will gradually shrink until it jumps to the hamburger menu.
Below you see how I have it now, the picture I need but I do not know how to do it
.site-nav {
width: 100%;
height: 100px;
display: flex;
}
.site-nav .nav-logo {
width: 200px;
height: 100px;
float: left;
display: flex;
}
.site-nav .nav-logo img {
width: 97px;
height: 47px;
margin: auto 0;
}
.site-nav .nav-links {
height: 100px;
float: right;
flex-grow: 1;
}
.site-nav .nav-links ul {
list-style: none;
margin: 0;
padding: 0;
height: 100px;
display: flex;
}
.site-nav .nav-links ul li {
float: left;
margin: auto;
padding-left: 16px;
}
.site-nav .nav-links ul li:not(:last-child) {
padding-right: 16px;
}
<nav class="site-nav">
<div class="container">
<div class="nav-logo">
<img src="logo.png" alt="">
</div>
<div class="nav-links">
<ul class="nav-list">
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
</nav>
You can use nested flexboxes and media queries to get the desired result. I used dummy images for the logo and the hamburger.
ul {
list-style: none;
margin: 0;
}
.site-nav {
width: 100%;
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
width: 80%;
margin: 0 auto;
}
.nav-links {
display: none;
}
.nav-links .nav-list {
display: flex;
flex-wrap: no-wrap;
}
.mobile-menu {
position: relative;
}
.mobile-menu .nav-list {
display: none;
position: absolute;
bottom: -90px;
left: -40px;
}
.mobile-menu:hover>.nav-list {
display: inline-block;
}
.nav-links .nav-list>li:not(:last-child) {
margin-right: 1rem;
}
#media screen and (min-width: 500px) {
.mobile-menu {
display: none;
}
.nav-links {
display: inline-block;
}
}
<nav class="site-nav">
<div class="container">
<div class="nav-logo">
<img src="https://via.placeholder.com/50x50" alt="">
</div>
<div class="mobile-menu">
<img src="https://via.placeholder.com/30x30" alt="">
<ul class="nav-list">
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
<div class="nav-links">
<ul class="nav-list">
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
<div class="nav-links">
<ul class="nav-list">
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
</nav>
How about the following example. With css grid it's easy to specify columns. With extra properties like justify-content you can specify how the columns are spaced.
.site-nav {
width: 100%;
height: 100px;
}
.site-nav .container {
display: grid;
grid-template-columns: 200px 1fr 1fr;
}
.site-nav .nav-logo {
grid-column: 1;
width: 200px;
height: 100px;
float: left;
display: flex;
}
.site-nav .nav-logo img {
width: 97px;
height: 47px;
margin: auto 0;
}
.site-nav .nav-links {
grid-column: auto;
}
.site-nav {
list-style-type: none;
}
.site-nav li {
display: inline-block;
}
<nav class="site-nav">
<div class="container">
<div class="nav-logo">
<img src="https://cdn.pixabay.com/photo/2018/08/19/19/56/peacock-feathers-3617474_960_720.jpg" alt="">
</div>
<div class="nav-links">
<ul class="nav-list">
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
<div class="nav-links">
<ul class="nav-list">
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
</nav>
Related
I am try to put the div nav2 on the same line as nav 1 but it just not going up what is the problem i even try float but it not working also
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
width: 100%;
height: 100vh;
}
#navbar {
position: fixed;
width: 100%;
display:
}
#navbar ul {
list-style: none;
}
#navbar ul li {
display: inline-block;
padding: 10px 5px 0px 20px;
}
#nav2 {
float: right;
}
<div id="main">
<div id="navbar">
<div id="nav1">
<ul>
<li>How it works</li>
<li>Why Company?</li>
<li>Pricing</li>
<li>About us</li>
<li>Resource center</li>
</ul>
</div>
<div id="nav2">
<ul>
<li>Get stated</li>
<li>Log in</li>
</ul>
</div>
</div>
<div id="head">
<div>
<h3>Company</h3>
</div>
<div>
<h1>Invert Like a idiot</h1>
</div>
<div>
<p>because money is lame</p>
</div>
</div>
</div>
I expect that Both "nav1" and "nav2" on the name line just like normal navbar but i want "nav2" on the right side that why i make it div "nav2"
This is probably what you want to do :
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100vh;
}
#navbar {
position: fixed;
width: 100%;
display: grid;
grid-template-columns: auto auto;
height: 50px;
}
#nav1 ul, #nav2 ul {
display: grid;
grid-gap: 20px;
grid-auto-columns: minmax(min-contant, max-content);
grid-auto-flow: column;
height: 100%;
align-items: center;
list-style: none;
}
#nav1 ul {
padding-left: 20px;
justify-content: left;
}
#nav2 ul {
padding-right: 20px;
justify-content: right;
}
#head {
padding: 50px 20px 0 20px;
}
<html>
<head></head>
<body>
<div id="main">
<div id="navbar">
<div id="nav1">
<ul>
<li>How it works</li>
<li>Why Company?</li>
<li>Pricing</li>
<li>About us</li>
<li>Resource center</li>
</ul>
</div>
<div id="nav2">
<ul>
<li>Get stated</li>
<li>Log in</li>
</ul>
</div>
</div>
</div>
</body>
</html>
I want to create a navigation panel like this
but I have a problem with img I can't put it in the middle
here is my code:
.leftNav {
text-align: right;
position: fixed;
width: 49%;
top: 0;
left: 0;
}
.rightNav {
position: fixed;
width: 49%;
top: 0;
right: 0;
left: auto;
}
.nav {
margin-top: 10px;
}
.nav li {
display: inline-block;
margin-left: 35px;
}
.nav li:first-child {
margin-left: 0;
}
.nav li a {
text-decoration: none;
color: white;
padding: 5px 0px;
text-transform: uppercase;
}
.wrapLogo {}
.logo {
height: 100px;
width: auto;
}
<header>
<div class="wrapNav">
<nav class="leftNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
<div class="wrapLogo">
<img src="./style/img/xxx.png" alt="" class="logo">
</div>
<nav class="rightNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
</div>
</header>
Thanks for all your help 😄
The best and simplest solution is to use flexbox.
You should put flex on the root div (.wrapNav) then to vertically align add align-items: center;.
.wrapNav {
display: flex;
align-items: center;
justify-content: center;
}
.nav {
display: flex;
/* RESET THE LIST */
list-style: none;
padding: 0;
margin: 0;
}
.nav li a{
display: block; /* MUST BECAUSE OF THE PADDING */
text-decoration: none;
color: red;
padding:0px 5px;
text-transform: uppercase;
}
.wrapLogo {
margin: 0 10px;
}
.logo {
height: 100px;
width: auto;
}
<header>
<div class="wrapNav">
<nav class="leftNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
<div class="wrapLogo">
<img src="http://via.placeholder.com/350x150" class="logo">
</div>
<nav class="rightNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
</div>
</header>
You can do it with the Flexbox:
body {margin: 0}
.wrapNav {
display: flex; /* displays flex-items (children) inline */
justify-content: center; /* centers them horizontally */
align-items: center; /* and vertically */
background: Aquamarine;
}
img {
display: block; /* removes bottom margin/whitespace */
width: 100%; /* responsiveness */
}
.nav {
display: flex;
justify-content: space-between;
list-style: none;
}
.nav > li {
margin: 0 15px;
}
.nav li a {
text-decoration: none;
color: #000;
padding: 5px 0px;
text-transform: uppercase;
}
/* addition */
#media (max-width: 568px) { /* adjust to your needs */
.wrapNav {flex-direction: column} /* stacks flex-items vertically */
}
<header>
<div class="wrapNav">
<nav class="leftNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
<img src="http://placehold.it/200x100" alt="" class="logo">
<nav class="rightNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
</div>
</header>
Something like this?
.leftNav {
width:40%;
top: 0;
left: 0;
}
.rightNav {
width:40%;
top: 0;
right: 0;
left: auto;
}
.nav {
margin-top: 10px;
}
.nav li{
display: inline-block;
margin-left: 35px;
}
.nav li:first-child {
margin-left: 0;
}
.nav li a{
text-decoration: none;
color: white;
padding: 5px 0px;
text-transform: uppercase;
}
.wrapLogo {
width:20%;
}
.wrapNav{
display: flex;
}
.logo {
height: 100px;
width: auto;
}
<header style="background-color: black;">
<div class="wrapNav">
<nav class="leftNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
<div class="wrapLogo">
<img src="http://via.placeholder.com/150x150" alt="" class="logo">
</div>
<nav class="rightNav">
<ul class="nav">
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
</nav>
</div>
</header>
I want something like this:
+-------------------------------------------------------------------+
| |
| LOGO Search_box... ITEM_1 ITEM_2 ITEM_3 |
| |
+-------------------------------------------------------------------+
The LOGO is an image. Search_box is an input text and ITEM_X an orizontally list item.
I tried this, but the logo doesn't stay where I want: https://jsfiddle.net/mna4de2n/
Note: I did not implement the input text yet.
CSS:
header{
width: 100%;
height: auto;
text-align: center;
display: inline-block;
}
header ul {
list-style-type: none;
text-align: center;
padding: 0.5vw;
overflow: hidden;
}
header li {
display: inline;
}
header li a{
display: inline-block;
color: #262626;
text-align: center;
padding: 0.5vh 0.5vw;
text-decoration: none;
}
header .left {
padding-left: 15%;
float: left;
}
header .right {
float: right;
padding-right: 25%;
}
header img {
width: 10%;
}
HTML:
<header>
<div class="left">
<li><img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png"></li>
</div>
<div class="right">
<ul>
<li><a class="active" href="#home">Matcha</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</header>
Why not use flexbox?
header {
width: 100%;
height: auto;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
align-items: center;
}
header img {
width: 50%;
}
header .left {
width: 30%;
}
header .right {
width: 70%;
display: flex;
justify-content: flex-end;
}
header ul {
list-style-type: none;
padding: 0.5vw;
overflow: hidden;
display: flex;
}
header li a {
color: #262626;
padding: 0.5vh 0.5vw;
text-decoration: none;
}
header input {
height: 30px;
align-self: center;
}
<header>
<div class="left">
<img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png">
</div>
<div class="right">
<input type="search">
<ul>
<li><a class="active" href="#home">Matcha</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</header>
<header>
<div class="right">
<ul>
<li><a class="active" href="#home">Matcha</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
<div class=""> <!-- You do not need this class here, now all you need to do is work on centering your menu. -->
<img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png">
</div>
I moved your logo after the right floated menu. and removed the li tag from the logo and the class for that div (float left is not needed.).
You need to set the image width to pixels, instead of percentage, this is making the parent of the image to take the full width of the header. Which is causing the issue. Also removing the li tag wrapping the image, since it is of no use.
Before:
header img {
width: 10%;
}
<div class="left">
<li><img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png"></li>
</div>
After:
header img {
width: 100px;
}
<div class="left">
<img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png">
</div>
Note: Please view the demo in full screen to see the change.
header {
width: 100%;
height: auto;
text-align: center;
display: inline-block;
}
header ul {
list-style-type: none;
text-align: center;
padding: 0.5vw;
overflow: hidden;
}
header li {
display: inline;
}
header li a {
display: inline-block;
color: #262626;
text-align: center;
padding: 0.5vh 0.5vw;
text-decoration: none;
}
header .left {
padding-left: 15%;
float: left;
}
header .right {
float: right;
padding-right: 25%;
}
header img {
width: 100px;
}
<header>
<nav>
<div class="left">
<img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png">
</div>
<div class="right">
<ul>
<li><a class="active" href="#home">Matcha</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</nav>
</header>
I have kept the li under ul, instead of div and changed the image size to pixels.
<div class="left">
<ul>
<li>
<img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png">
</li>
</ul>
</div>
header {
width: 100%;
height: auto;
text-align: center;
display: inline-block;
}
.left ul{
padding:0;
}
header ul {
list-style-type: none;
text-align: center;
padding: 0.5vw;
overflow: hidden;
}
header li {
display: inline;
}
header li a {
display: inline-block;
color: #262626;
text-align: center;
padding: 3vh 0.5vw;
text-decoration: none;
}
header .left {
padding-left: 15%;
float: left;
}
header .right {
float: right;
padding-right: 25%;
}
header img {
width: 80px;
}
<header>
<nav>
<div class="left">
<ul>
<li>
<img src="http://logok.org/wp-content/uploads/2017/05/YouTube-logo-2017-logotype.png">
</li>
</ul>
</div>
<div class="right">
<ul>
<li><a class="active" href="#home">Matcha</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</nav>
</header>
Fixed div is getting down when I give margin-top to the div below it...why?
* {
margin: 0;
padding: 0;
}
.header_bg {
width: 100%;
height: 100px;
position: fixed;
background: black
}
.container {
width: 960px;
height: auto;
margin: 0 auto
}
ul.menu {
list-style: none;
}
ul.menu li {
display: inline-block
}
ul.menu li a {
text-decoration: none;
color: white
}
.content {
margin-top: 140px
}
<div class="header_bg">
<div class="container">
<ul class="menu">
<li>Home
</li>
<li>About
</li>
<li>Service
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">
/* Content Goes here*/
</div>
</div>
you need to add top:0 to your .header_bg, see more about position
* {
margin: 0;
padding: 0;
}
.header_bg {
width: 100%;
height: 100px;
position: fixed;
background: black;
top:0
}
.container {
width: 960px;
height: auto;
margin: 0 auto
}
ul.menu {
list-style: none;
}
ul.menu li {
display: inline-block
}
ul.menu li a {
text-decoration: none;
color: white
}
.content {
margin-top: 140px
}
<div class="header_bg">
<div class="container">
<ul class="menu">
<li>Home
</li>
<li>About
</li>
<li>Service
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">
/* Content Goes here*/
</div>
</div>
I've been trying to create a navigation bar which consists of three pieces, a list to the left of the centered logo, the logo itself and a list to the right of the logo. I've tried absolutely positioning the logo and floating the lists however this leads to the logo overlaying the lists when the width of the browser is altered.
Any suggestions would be much appreciated, JSFiddle included below :-).
JSFiddle
HTML
<div class="navigation">
<div class="container-1020">
<ul>
<li>Home</li>
<li>Work</li>
<li>Contact</li>
<li>Blog</li>
</ul>
<div class="nav-logo">
<img src="http://placehold.it/200x60"/>
</div>
<ul>
<li>01234 123456</li>
</ul>
</div>
</div>
CSS
.navigation {
background: #222222;
}
.container-1020 {
max-width: 1020px;
min-width: 500px;
margin: 0 auto;
}
ul {
color: #fff;
margin: 0;
list-style-type: none;
}
li {
display: inline;
margin-right: 10px;
}
li:last-child {
margin-right: 0 !important;
}
.logo-container {
width: 200px;
height: 60px;
}
This might work for youFIDDLE
css:
* {
margin: 0;
}
a {
color: #ffffff;
text-decoration: none;
}
.navigation {
background: #222222;
}
.container-1020 {
max-width: 1020px;
min-width: 500px;
margin: 0 auto;
}
ul {
color: #fff;
list-style-type: none;
display: inline-block;
width: 30%;
}
ul:last-child {
text-align: right;
}
.nav-logo {
display: inline-block;
width: 30%;
}
html:
<div class="navigation">
<div class="container-1020">
<ul class="left">
<li>Home
</li>
<li>Work
</li>
<li>Contact
</li>
<li>Blog
</li>
</ul>
<div class="nav-logo">
<img src="http://placehold.it/200x60" />
</div>
<ul class="right">
<li>01234 123456</li>
</ul>
</div>
</div>
well for one, correct your class name for the logo, is it .nav-logo or .logo-container
then set your ul's and whichever logo container class you decide on to display:inline-block