I have a brand image in the center of the navbar and one menu on either side of it. I want to align both menus to the image (menu on the right side of the image is left aligned and vise versa). I managed this on the right menu but I can't align the menu on the left side.
What I have right now, looks good on large screens but does not condense properly on a smaller screen (on the left side, the right is correct).
CSS
.navbar{
background-color: white;
border: 0px;
height: 200px;
}
.navbar-middle {
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: auto;
}
.navbar-left {
padding-right: 10%;
padding-top: 90px;
width: 50%;
}
.navbar-right {
padding-left: 3%;
padding-top: 90px;
width: 50%;
}
.navbar-left li {
padding-left: 20%;
}
.navbar-right li {
padding-left: 15%;
}
HTML
<ul class="nav navbar-nav navbar-left">
<li>Home</li>
<li>Our Vision</li>
<li>The Team</li>
</ul>
<ul class="nav navbar-middle">
<li><img src="200.jpg"></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Portfolio</li>
<li>FAQs</li>
<li>Contact</li>
</ul>
Thanks for the help!
I think you are after something like this
ul{
list-style: none;
padding: 0;
}
.navbar{
background-color: white;
border: 0px;
height: 200px;
display: flex;
flex-wrap: nowrap;
justify-content: center;
align-items: flex-end;
}
.navbar-left {
display: flex;
flex-wrap: nowrap;
justify-content: center;
align-items: flex-end;
}
.navbar-middle {
margin: 0 20px;
}
.navbar-right {
display: flex;
flex-wrap: nowrap;
justify-content: center;
align-items: flex-start;
}
.navbar-left li {
margin-left: 20px;
white-space:nowrap;
}
.navbar-right li {
margin-right: 20px;
white-space:nowrap;
}
<div class="navbar">
<ul class="nav navbar-nav navbar-left">
<li><a class="pull-right" href="#">Home</a></li>
<li>Our Vision</li>
<li>The Team</li>
</ul>
<img class="nav navbar-middle" src="https://placehold.it/200x100/894567/ffffff?text=Logo">
<ul class="nav navbar-nav navbar-right">
<li>Portfolio</li>
<li>FAQs</li>
<li>Contact</li>
</ul>
</div>
From what I can see from inspecting the elements, your three ul seem to be overlapping.
So I changed the widths of the navbar-left and navbar-right classes to 45% each and added a width specification for the image, i.e. img src="200.jpg" size=10%.
From what I can tell, your left ul looked to be right-aligned not because of class="pull-right" but because of your .navbar-left li { padding-left: 20%; }. You can do the same for your navbar-right, i.e. .navbar-right li { padding-right: 20%; }.
This is the result: http://codepen.io/anon/pen/OMreKN. Not sure if it is what you're looking for.
Here's another option: JSFiddle
<div class="wrapper">
<ul class="nav navbar-nav navbar-left">
<li><a class="pull-right" href="#">Home</a></li>
<li>Our Vision</li>
<li>The Team</li>
</ul>
<ul class="nav navbar-middle">
<li><img src="200.jpg"></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Portfolio</li>
<li>FAQs</li>
<li>Contact</li>
</ul>
</div>
body {
margin: 0;
}
.wrapper {
background-color: gray;
font-size: 0;
width: 100%;
height: 100px;
text-align: center;
}
img {
width: 100%;
}
.nav {
display: inline-block;
font-size: initial;
list-style: none;
padding: 0;
vertical-align: middle;
}
li {
display: inline-block;
width: 75px;
}
.navbar-left, .navbar-right {
width: 45%;
}
.navbar-middle {
width: 10%;
}
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 am trying to center a logo so that it is constantly in the center of my navigation bar, regardless of how many navigation links there are.
This would be easy enough for me if the items at the sides were both even, for example 2 links on the left and 2 on the right, but I'm trying to get 3 on the left and 2 on the right with the centered logo.
Is it possible to center the image using flexbox properties or would I have to go about it a different way, like involving absolute/relative positioning?
header.main-header {
background: url("../images/slides/slide-1.jpg") no-repeat 75%/cover;
height: 100vh;
}
nav.nav-bar {
background-color: tomato;
}
ul.container {
display: flex;
align-items: center;
justify-content: space-around;
padding: 0;
}
ul.container li {
list-style-type: none;
}
li.logo img {
max-width: 125px;
}
<header class="main-header">
<nav class="nav-bar">
<ul class="container">
<li>My Story</li>
<li>Wines</li>
<li>How to Order</li>
<li class="logo"><img src="http://placeimg.com/640/480/any" alt="Wines"></li>
<li>Personal Sommelier</li>
<li>Contact</li>
</ul>
</nav>
<p style="text-align: center;">|<br>(Center)</p>
</header>
Thank you in advance.
Have a great day. :)
An idea is to use the logo as background and centred then you rely on some margin to adjust the menu elements:
header.main-header {
height: 100vh;
}
nav.nav-bar {
background-color: tomato;
}
ul.container {
display: flex;
align-items: center;
padding: 0;
background:url(http://placeimg.com/640/480/any) center/contain no-repeat;
min-height:100px;
}
ul.container li {
list-style-type: none;
margin:0 2%;
}
ul.container li:nth-child(3) {
margin-right:auto;
}
<header class="main-header">
<nav class="nav-bar">
<ul class="container">
<li>My Story</li>
<li>Wines</li>
<li>How to Order</li>
<li>Personal Sommelier</li>
<li>Contact</li>
</ul>
</nav>
<p style="text-align: center;">|<br>(Center)</p>
</header>
But in case you can adjust your HTML you may simply split the menu into 2 parts:
header.main-header {
height: 100vh;
}
nav.nav-bar {
background-color: tomato;
display:flex;
align-items:center;
}
ul.container {
display: flex;
align-items: center;
justify-content:space-around;
flex:1;
padding: 0;
}
img {
max-width:100px;
}
ul.container li {
list-style-type: none;
margin:0 2%;
}
<header class="main-header">
<nav class="nav-bar">
<ul class="container">
<li>My Story</li>
<li>Wines</li>
<li>How to Order</li>
</ul>
<img src="http://placeimg.com/640/480/any" >
<ul class="container">
<li>Personal Sommelier</li>
<li>Contact</li>
</ul>
</nav>
<p style="text-align: center;">|<br>(Center)</p>
</header>
I'm trying to have the elements in the middle 1240px of the screen using a wrapper, however, when I add the wrapper, the .space <li> element stops shrinking when I shrink down the page making my sign in button and sign out button disappear in the right side of the page. Also I've been wondering whether using an empty <li> with flex: 1 is the correct way of creating the space in between the first 3 <li> elements and the last 2.
.container {
display: flex;
}
.container>li {
padding: 10px;
text-align: center;
font-size: 1em;
color: white;
box-sizing: border-box;
background-color: black;
list-style-type: none;
}
.space {
flex: 1;
}
.wrapper {
width: 1240px;
margin: 0 auto;
height: 100%;
}
<nav>
<div class='wrapper'>
<ul class="container">
<li>Images</li>
<li>Albums</li>
<li>Tags</li>
<li class='space'></li>
<li>Log In</li>
<li>Sign Up</li>
</ul>
</div>
</nav>
You need to use percent to make it responsive.
Or, add max-width: 100%; if you want to maintain width: 1240px;
.container {
display: flex;
}
.container>li {
padding: 10px;
text-align: center;
font-size: 1em;
color: white;
box-sizing: border-box;
background-color: black;
list-style-type: none;
}
.space {
flex: 1;
}
.wrapper {
width: 100%;
margin: 0 auto;
height: 100%;
}
<nav>
<div class='wrapper'>
<ul class="container">
<li>Images</li>
<li>Albums</li>
<li>Tags</li>
<li class='space'></li>
<li>Log In</li>
<li>Sign Up</li>
</ul>
</div>
</nav>
Use width: 100%; to nav and wrapper
.container {
display: flex;
}
.container>li {
padding: 10px;
text-align: center;
font-size: 1em;
color: white;
box-sizing: border-box;
background-color: black;
list-style-type: none;
}
.space {
flex: 1;
}
.wrapper {
width: 1240px;
margin: 0 auto;
height: 100%;
width: 100%;
}
nav{
width: 100%;
}
<nav>
<div class='wrapper'>
<ul class="container">
<li>Images</li>
<li>Albums</li>
<li>Tags</li>
<li class='space'></li>
<li>Log In</li>
<li>Sign Up</li>
</ul>
</div>
</nav>
I have a list of items and I have used the toggle to appear when the media resolution is at 768px. The list was coming in one column and now I made it display in a row. As I have 5 lists in my menu I want 2 lists to appear in one row at 360px resolution and at 640px resolution 4 items can be shown in a row. so based on the resolution width it must take lists in a row and rest as dropdown rows.
.leftSide ul:first-child li a{
display: inline-block;
padding: 20px 62px;
color:red;
cursor: pointer;
font-family:segoeuib;
font-size:16px;
}
.leftSide ul {
margin: 0px;
}
.leftSide ul:first-child li a:hover,.nav>li>a:focus, .nav>li>a:hover {
color: #b755ff !important ;
background-color: white !important;
}
li.fav a:hover {
margin-left: 9px;
}
#media only screen and (max-width:768px) {
.menu {
display: flex;
flex-direction: row;
}
span.caret.arrow {
margin-top: -40px;
margin-left: 58px;
}
}
<div class="nav navbar-nav navbar-left leftSide">
<ul class="nav navbar-nav menu">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Browse<span class="caret arrow"></span></a></li>
<li>Map</li>
<li>Interviews</li>
<li>Places</li>
<li class="fav">My Favourites</li>
</ul>
</div>
You have to set the flex-basis property to your menu>li according to your requirement. Try below css.
Stack Snippet
.nav.navbar-nav.menu {
list-style: none;
padding: 0;
}
#media only screen and (max-width:640px) {
.menu {
display: flex;
flex-wrap: wrap;
}
.menu li {
flex-basis: 25%;
text-align: center;
}
}
#media only screen and (max-width:360px) {
.menu {
display: flex;
flex-wrap: wrap;
}
.menu li {
flex-basis: 50%;
text-align: center;
}
}
<div class="nav navbar-nav navbar-left leftSide">
<ul class="nav navbar-nav menu">
<li>Browse</li>
<li>Map</li>
<li>Interviews</li>
<li>Places</li>
<li class="fav">My Favourites</li>
</ul>
</div>
I am using the following code in my header to display my logo and my navigation. I vertically centered my text with line-height: 90px; but when I try to give my logo vertical-align: middle; it doesn't seem to work. What am I doing wrong?
header {
max-width: 960px;
height: 90px;
margin: 0 auto;
line-height: 90px;
background: #444444;
}
header img {
width: 59px;
height: 32px;
float: left;
}
nav {
float: right;
}
nav ul li {
display: inline-block;
}
nav li:not(:last-child) {
margin: 0px 50px 0px 0px;
}
<header>
<img src="images/logo.png" alt="Logo">
<!-- Bild fehlt noch - SVG -->
<nav>
<ul>
<li>Start
</li>
<li>About me
</li>
<li>Services
</li>
<li>Portfolio
</li>
<li>Contact
</li>
</ul>
</nav>
</header>
Flexbox can do that:
header {
max-width: 960px;
height: 90px;
margin: 0 auto;
line-height: 90px;
background: #444444;
display: flex;
justify-content: space-between;
align-items: center;
}
header img {
width: 59px;
height: 32px;
}
nav {} nav ul li {
display: inline-block;
}
nav li:not(:last-child) {
margin: 0px 50px 0px 0px;
}
nav ul li a {
color: white;
}
<header>
<img src="http://www.fillmurray.com/59/32" alt="Logo">
<!-- Bild fehlt noch - SVG -->
<nav>
<ul>
<li>Start
</li>
<li>About me
</li>
<li>Services
</li>
<li>Portfolio
</li>
<li>Contact
</li>
</ul>
</nav>
</header>