Split up li in navbar to different sides using flexbox - html

I'm trying to set up my navbar so I have the github and linkedin imgs/links on the left side, but I want to keep the bio/portfolio/contact links on the right.
I'm using flexbox on the nav, but I'm not sure if I can split up this ul such that the lis are on different sides.
I'm using flexbox on the nav, but I'm not sure if I can split up this ul such that the lis are on different sides since I have justify-content: space-between on.
I have no idea what I should change to make this work.
fiddle: https://jsfiddle.net/Ginsole/4svpeLq9/
nav {
background-color: #265B8B;
height:60px;
color: white;
position: fixed;
top:0;
left:0;
right:0;
width: 100%;
display: flex;
justify-content: space-between;
}
nav p {
font-weight: bold;
margin-left: 1em;
color: white;
text-align: left;
margin-top:1.25em;
font-size: 1em;
}
nav a {
color: white;
font-size: 1em;
font-weight: bold;
}
nav ul {
margin-bottom: 5em;
display: flex;
margin-top: 1.25em;
}
nav li {
list-style: none;
margin-right: 1em;
}
nav li.github {
margin-left: auto;
}
nav img {
width: 25px;
height: 25px;
margin-right: 10px;
}
.menu-toggle {
position: absolute;
padding: 0.8 em;
top: 1em;
right: 1em;
cursor: pointer;
}
<nav>
<p>STEVEN KANG</p>
<ul>
<li class="rightLinks"><a data-scroll-target="contact">Contact</a></li>
<li class="rightLinks"><a data-scroll-target="projects">Portfolio</a></li>
<li class="rightLinks"><a data-scroll-target="bio">Bio</a></li>
<li class="leftLinks"><img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"></li>
<li class="leftLinks"><img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/LinkedIn_logo_initials.png"></li>
</ul>
<div class="menu-toggle">
<i class="fa fa-bars"></i>
</div>
</nav>
I expect to have the two img links on the left and keep the rest of the links on the right side.

Here is updated version
https://jsfiddle.net/chille1987/236x0ntq/9/
nav {
background-color: #265B8B;
height:60px;
color: white;
position: fixed;
top:0;
left:0;
right:0;
width: 100%;
display: flex;
}
nav p {
font-weight: bold;
margin-left: 1em;
color: white;
text-align: left;
margin-top:1.25em;
font-size: 1em;
}
nav a {
color: white;
font-size: 1em;
font-weight: bold;
}
nav ul {
flex: 1;
margin-bottom: 5em;
display: flex;
flex-direction: row-reverse;
margin-top: 1.25em;
}
nav li {
list-style: none;
margin-right: 1em;
}
nav li.linkedin {
margin-right: auto;
}
nav img {
width: 25px;
height: 25px;
margin-right: 10px;
}
.menu-toggle {
position: absolute;
padding: 0.8 em;
top: 1em;
right: 1em;
cursor: pointer;
}
<nav>
<p>STEVEN KANG</p>
<ul>
<li class="rightLinks contact"><a data-scroll-target="contact">Contact</a></li>
<li class="rightLinks"><a data-scroll-target="projects">Portfolio</a></li>
<li class="rightLinks"><a data-scroll-target="bio">Bio</a></li>
<li class="leftLinks linkedin"><img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/LinkedIn_logo_initials.png"></li>
<li class="leftLinks github"><img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"></li>
</ul>
<div class="menu-toggle">
<i class="fa fa-bars"></i>
</div>
</nav>

Related

How to align nav-item to center of page

* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
html {
font-size: 10px;
}
.clearfix::after {
display: block;
clear: both;
content: "";
}
nav {
position: absolute;
margin: auto;
.nav-container {
padding-right: 2rem;
padding-left: 2rem;
padding-bottom: 2rem;
margin-top: 2rem;
margin-right: auto;
margin-left: auto;
.nav-list {
list-style-type: none;
.nav-item {
display: inline-block;
padding-left: 2rem;
padding-right: 2rem;
font-size: 1.2rem;
.nav-link {
text-decoration: none;
color: #fbfdff;
}
}
}
}
}
header {
background-color: #313131;
height: 50rem;
}
<nav>
<div class="nav-container">
<ul class="nav-list">
<li class="nav-item">HOME</li>
<li class="nav-item">ABOUT ME</li>
<li class="nav-item">PROJECTS</li>
<li class="nav-item">CONTACT</li>
</ul>
</div>
</nav>
How can i align nav-item to center of the nav-container ? Navbar should has transparent background, so i wanted to add position: absolute; style to nav element. Also all nav-item s should appear side by side. That's why i added display: inline-block; style to them.
Set the width of the nav to full width, and then use text-align: center.
nav {
width: 100%;
text-align: center;
}
there are so many ways to that but I'll prefer to use flexbox or css grid in
'nav-list'.
here's the example using felxbox:
.nav-list {
display:flex;
justify-content:center;
align-items: center; (if want to align vertically as well)
list-style-type: none;
}
it will resolve your problem, copy paste and enjoy.
just add this in css and it will be in center
.nav-list{
display: grid;
justify-content: center;
}
your styles are not correct css syntax.
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
html {
font-size: 10px;
}
.clearfix::after {
display: block;
clear: both;
content: "";
}
.nav-container {
padding-right: 2rem;
padding-left: 2rem;
padding-bottom: 2rem;
margin-top: 2rem;
margin-right: auto;
margin-left: auto;
}
.nav-list {
list-style-type: none;
}
.nav-item {
display: inline-block;
padding-left: 2rem;
padding-right: 2rem;
font-size: 1.2rem;
}
.nav-link {
text-decoration: none;
}
header {
background-color: #313131;
height: 50rem;
}
<nav>
<div class="nav-container">
<ul class="nav-list">
<li class="nav-item">HOME</li>
<li class="nav-item">ABOUT ME</li>
<li class="nav-item">PROJECTS</li>
<li class="nav-item">CONTACT</li>
</ul>
</div>
</nav>

Push a div to the right

I'm coding a menu in french but I need to move all the buttons (Home, About us...) to the right.
I tried with float: right; but it doesn't work.
Here is my Result :
My Result
The <a> Home, Informations, etc.. are in a div. It's this div that i want to push right !
My Objective :
My Objective
My Code:
/*
==============================
NAVBAR
==============================
*/
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #9ebd11/*55d6aa*/
;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
/*padding: 10px 0;*/
}
nav {
float: right;
}
nav #navbar-ul {
margin: 0;
padding: 0;
list-style: none;
}
nav .navbar-li {
display: inline-block;
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav .navbar-button {
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav .navbar-button:hover {
color: #000;
}
nav .navbar-button::before {
content: '';
display: block;
height: 5px;
background-color: #444;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav .navbar-button:hover::before {
width: 100%;
}
nav #register-li {
/*display: inline-block;*/
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav #register-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav #login-li {
/*display: inline-block;*/
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav #login-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
ul {
list-style-type: none;
}
nav,
.container {
display: flex;
}
.connection {
line-height: 2;
}
<header>
<div class="container">
<h1 class="logo">
<img src="images/Logo/logo_gp_.png" width="100" alt="Description de l'image">
</h1>
<nav>
<ul id="navbar-ul">
<li class="navbar-li">Home</li>
<li class="navbar-li">Informations</li>
<li class="navbar-li">About us</li>
</ul>
<ul class="connection">
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</nav>
</div>
</header>
Thanks
Float won't work because your container is a flex-container.
Just use:justify-content:space-between`
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #9ebd11/*55d6aa*/
;
}
nav #navbar-ul {
margin: 0;
padding: 0;
list-style: none;
}
nav .navbar-li {
display: inline-block;
padding-top: 23px;
position: relative;
}
nav .navbar-button {
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav .navbar-button:hover {
color: #000;
}
nav .navbar-button::before {
content: '';
display: block;
height: 5px;
background-color: #444;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav .navbar-button:hover::before {
width: 100%;
}
nav #register-li {
/*display: inline-block;*/
margin-left: 70px;
padding-top: 23px;
position: relative;
}
nav #register-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav #login-li {
position: relative;
}
nav #login-button {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
ul {
list-style-type: none;
}
nav,
.container {
display: flex;
justify-content: space-between;
}
.connection {
line-height: 2;
}
<header>
<div class="container">
<h1 class="logo">
<img src="images/Logo/logo_gp_.png" width="100" alt="Description de l'image">
</h1>
<nav>
<ul id="navbar-ul">
<li class="navbar-li">Home</li>
<li class="navbar-li">Informations</li>
<li class="navbar-li">About us</li>
</ul>
<ul class="connection">
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</nav>
</div>
</header>
Bootstrap's "Container" class has a max-width of something like 1800px(not certain of exact px count).
Try using "container-fluid". This should allow the nav items to move to the far right but will probably move your logo to the far left because of your .logo float-left css.
You can give the logo a margin-left that works for you.
Edit: I just noticed you've defined your own .container class in the css. And margin set to 0 auto. This is going to center your content within the container class and give you max width of 80% so your content won't reach the far right side of the browser unless you set this items to "position:absolute" and then give them the necessary margins.
Try changing your nav class from:
nav{
floaf: right;
}
to:
nav{
position: absolute;
right: 20px;
top: 0px;
}
This should force your nav element to position it's right 20px left of the parent elements right. Tested in chrome.
remove the float: right from your .nav and add float:left from .logo
Now add display:flex to your .logo and for your container add:
.container{
justify-content: space-between;
}
I have not tested this. Let me know if this is what you wanted.

How do I shift text over in an inline-block in CSS?

I am trying to move the Status/Actions Text over to the left but no matter how much I mess with the CSS nothing works!
What it is supposed to look like
What I have so far
HTML code for that section
CSS for that section
.top {
background: #1b1b1e;
width: 1650px;
margin: auto;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
margin-right: 10em;
}
<div class="top">
<ul>
<li>Link</li>
<li>Status</li>
<li>Action</li>
</ul>
</div>
.top {
background: #1b1b1e;
width: 100%;
margin: auto;
float: left;
padding: 10px 0;
}
.top ul {
margin: 0px;
padding: 0px;
}
.top li {
list-style-type: none;
float: left;
width: 230px;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
}
.statusText {
float: right !important;
}
.actionText {
float: right !important;
max-width: 149px;
}
<div class="top">
<ul>
<li class="linkText">Link</li>
<li class="actionText">Action</li>
<li class="statusText">Status</li>
</ul>
</div>
Please apply this :
.top {
background: #1b1b1e;
display: flex;
align-items: center;
justify-content: space-between;
}
.link-wrap {
width: 300px;
padding-left: 20px;
}
.top ul {
display: flex;
width: 400px;
justify-content: space-between;
list-style-type: none;
}
.top ul li {
padding-right: 25px;
}
.top ul li a,
.link-wrap a {
display: inline—block;
color: #9c9c9c;
text-decoration: none;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
}
.link-wrap a {
width: 300px;
}
<div class="top">
<div class="link-wrap">
Link
</div>
<ul>
<li>Status</li>
<li>Action</li>
</ul>
</div>
If any changes please let me know.
you can use flexbox order property:
https://www.w3schools.com/css/css3_flexbox.asp
If you are good to go with flex, a few lines of code will fix your issue.
display: flex;
.top {
background: #1b1b1e;
/* width: 1650px; */
width: 100%;
margin: auto;
}
ul {
display: flex;
}
li {
list-style: none;
}
.statusText {
margin-left: auto;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
/* margin-right: 10em; */
}
<div class="top">
<ul>
<li>Link</li>
<li class="statusText">Status</li>
<li>Action</li>
</ul>
</div>
If you are interested to go with display inline-block only, you can use the float property.
display: inline-block;
.top {
background: #1b1b1e;
/* width: 1650px; */
width: 100%;
margin: auto;
}
li {
display: inline-block;;
list-style: none;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
/* margin-right: 10em; */
}
.float-right {
float: right;
}
<div class="top">
<ul>
<li>Link</li>
<!-- Reversed Order -->
<li class="float-right">Action</li>
<li class="float-right">Status</li>
</ul>
</div>
.top {
background: #1b1b1e;
width: 1650px;
margin: auto;
}
ul{
display:flex;
flex-direction: row-reverse;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
margin-right: 10em;
}
<div class="top">
<ul>
<li>Link</li>
<li>Status</li>
<li>Action</li>
</ul>
</div>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.top {
background: #1b1b1e;
width: 100%;
margin: auto;
}
li {
display: inline-block;
}
li a {
display: inline—block;
/* padding: 1em; */
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
margin-right: 1em;
}
ul li:not(:first-child) {
float: right;
}
</style>
<body>
<div class="top">
<ul>
<li>Link</li>
<li>Status</li>
<li>Action</li>
</ul>
</div>
</body>
</html>
Another way to achieve what you want, But I would suggest just like others to use flex box :)

Remove whitespace from my navigation bar

This is my code (im a total noob in html) this code gives me whitespace on top and on the left of my navigation... do you guys have any idea of what im doing wrong?
div.nav {
background-color: black;
color: white;
font-size: 20px;
font-weight: bold;
position: fixed;
width: 100%;
text-align: center;
}
ul {
}
li {
display: inline-block;
list-style: none;
}
li a {
padding: 15px;
color: white;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Wat is D&B</li>
<li>D&B in Nederland</li>
</ul>
</div>
Added html
this is CSS. Add this
body{
padding: 0;
margin: 0;
}
body{
padding: 0;
margin: 0;
background-color: #e8e4e5;
}
div.nav {
background-color: black;
color: white;
font-size: 20px;
font-weight: bold;
position: fixed;
width: 100%;
text-align: center;
}
ul {
}
li {
display: inline-block;
list-style: none;
}
li a {
padding: 15px;
color: white;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Wat is D&B</li>
<li>D&B in Nederland</li>
</ul>
</div>
But you can set to nav div position fixed: it will help when you get scroll in content, but nav div all time will in top.
body{
padding: 0;
margin: 0;
}
.content{
margin-top: 60px;
height: 150vh;
background-color: #d2d29d;
}
div.nav {
position: fixed;
height: 60px;
background-color: black;
color: white;
font-size: 20px;
font-weight: bold;
position: fixed;
top: 0;
left: 0;
width: 100%;
text-align: center;
}
ul {
}
li {
display: inline-block;
list-style: none;
}
li a {
padding: 15px;
color: white;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Wat is D&B</li>
<li>D&B in Nederland</li>
</ul>
</div>
<div class="content">
Some text
</div>
Since you're using position:fixed; you can change you css to the following, which will force the navbar to be in the top-left corner of your page
div.nav {
background-color: black;
color: white;
font-size: 20px;
font-weight: bold;
position: fixed;
top:0; //<================= Add this
left:0; //<================= And add this
width: 100%;
text-align: center;
}
Ofcourse, there's many more ways. The above CSS will result in your whitespace being removed
div.nav {
background-color: black;
color: white;
font-size: 20px;
font-weight: bold;
position: fixed;
top:0; //<================= Add this
left:0; //<================= And add this
width: 100%;
text-align: center;
}
ul {
}
li {
display: inline-block;
list-style: none;
}
li a {
padding: 15px;
color: white;
}
<div class="nav">
<ul>
<li>Home</li>
<li>Wat is D&B</li>
<li>D&B in Nederland</li>
</ul>
</div>
Hope this helps!

Cant change <li> vertical position inside nav bar without affecting nav bar's size

So I try to change li's vertical position but when I do the nav bar height is affected as well. What is the way to actually do that without affecting nav bar's height?
Here's the code:
body {
margin: 0px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
padding-left: 5px;
padding-top: 10px;
background-color: #333;
overflow: hidden;
}
li {
float: left;
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
What is your goal here? To have the content centered or...?
It may be better to use flexbox here rather than set the padding-left: 850px; on your ul (also on your ul you could've used display: block; margin: 0 auto; to center it.) If you'd like, you can give your ul a defined height and use align-items to specify how it should be aligned vertically.
body {
margin: 0;
}
nav {
background-color: #333;
display: flex;
justify-content: center;
}
nav ul {
display: flex;
justify-content: center;
list-style: none;
margin: 0;
padding: 0;
height: 50px;
align-items: center;
}
li {
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<body>
<nav>
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
</nav>
</body>
You can add position: relative; and a value for bottom or top- in my snippet bottom: 4px;:
This reserves the space originally taken by the element (without position: relative;), but moves the element according to the top/bottom/left/right settings, without affecting other elements.
body {
margin: 0px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
padding-left: 5px;
padding-top: 10px;
background-color: #333;
overflow: hidden;
}
li {
float: left;
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
position: relative;
bottom: 4px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>