Centering Bootstrap navbar - css

I am new to css. I will like to center brand logo and also the links in the navbar.
HTML
<nav class="navbar navbar-expand-md center">
<a class="navbar-brand" href="http://www.dimsum.dk" target="_blank">
<img src={% static 'media/HIDDEN DIMSUM logo final.png'%} width="100" alt="">
</a>
<button class="navbar-toggler navbar-dark" type="button" data-toggle="collapse" data-target="#main-navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="main-navigation">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Book Table</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://www.dimsumbox.dk" target="_blank">
Order Dimsum Box</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://www.dimsumshop.dk" target="_blank">
Order Takeaway</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" target="_blank">
About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" target="_blank">
Contact</a>
</li>
</ul>
</div>
</nav>
CSS
.navbar {
background: #d48498;
}
.nav-link {
color: black;
font-size: 24px;
font-weight: bold;
}
.navbar.center .nav-item {
text-align: center;
display: inline-block;
vertical-align: middle;
}
This is how the navbar looks right now
I want to have the logo centered and the links appearing in a new line also centered so it looks like
Logo
Link 1 Link 2 Link 3 Link 4
I have tried justify center in css but it doesn't work.

Add this bit to your css
#media (min-width: 768px) {
.navbar {
flex-flow: wrap;
}
.navbar-brand {
width: 100%;
text-align: center;
}
.navbar-brand img {
height: 50px; /*Set a logo size*/
width: auto;
}
.navbar-collapse {
justify-content: center;
}
}

use justify content: center and display: flex in css
display: flex;
justify-content: center;
for reference https://www.w3schools.com/cssref/css3_pr_justify-content.asp

add this css after bootstrap.css:
.navbar-brand {
display: flex;
width: 100%;
justify-content: center !important;
}
.navbar {
flex-wrap: wrap !important;
justify-content: center !important;
}
.navbar-nav{
width:100%;
justify-content:center !important
}

Related

Flexbox justify-content: space-between with padding as the space rather than margin

I have the following design currently:
var totalWidth = 0;
$('.nav-item').each(function(index) {
totalWidth += parseInt($(this).width(), 10);
});
$('.nav-item').css('padding-left', ($('.navbar-nav').width() - totalWidth) / 10);
$('.nav-item').css('padding-right', ($('.navbar-nav').width() - totalWidth) / 10);
.navbar {
background-color: rgb(188 174 159);
font-family: source-serif-pro, serif;
font-weight: 700;
font-style: normal;
border-bottom: 3px solid white;
font-size: 22px;
padding-bottom: 0.7vw;
padding-top: 0.7vw;
max-height: 9vh;
}
.navbar-brand img {
height: 7.5vh;
}
.navbar-nav {
display: flex;
justify-content: space-between;
width: 100%;
margin-left: 1rem;
}
.nav-item {
font-size: 2vw;
background-color: #e4dbd1 !important;
display: flex;
height: calc(9vh - 3px);
}
.nav-link {
color: #731d2c !important;
display: flex;
align-self: center;
}
.nav-link.active {
color: #94253d !important;
}
.nav-item:hover {
background-color: #e4dbd1 !important;
}
#media screen and (min-width: 1200px) {
.nav-item {
font-size: 25px;
}
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<a class="navbar-brand" href="index.html"><img src="img/logo.svg"></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">
<li class="nav-item">
<a class="nav-link active" href="index.html">Map</a>
</li>
<li class="nav-item">
<a class="nav-link" href="timeline.html">Timeline</a>
</li>
<li class="nav-item">
<a class="nav-link" href="essays.html">Short Essays</a>
</li>
<li class="nav-item">
<a class="nav-link" href="bibliography.html">Bibliography</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
</ul>
</div>
</div>
</nav>
The lighter colour is what the intended hover effect will be.
At the moment I am using:
display: flex;
justify-content: space-between;
in order to create the spacing between the elements. This gives me even spacing which is ideal, however the lighter colour does not cover this areas as it is done via a margin.
I am wondering if this is possible to achieve via padding. I tried width 20% since there are 5 elements and 5x20%=100%, however it was odd having a 3 letter word like "Map" take up as much space as "Short Essays" which is much longer.
Any suggestions on how to achieve this would be ideal.
UPDATE:
I was able to achieve a solution using Javascript/Jquery as follows:
var totalWidth = 0;
$('.nav-item').each(function(index) {
totalWidth += parseInt($(this).width(), 10);
});
$('.nav-item').css('padding-left', ($('.navbar-nav').width() - totalWidth)/10);
$('.nav-item').css('padding-right', ($('.navbar-nav').width() - totalWidth)/10);
You can add flex for nav-item
Note that I'm using min-width: 992px because Bootstrap's tablet breakpoint is 992px
#media screen and (min-width: 992px) {
.nav-item {
font-size: 25px;
flex: 0 1 20%;
justify-content: center;
}
/*For hovering testing*/
.nav-item:hover {
background-color: red !important;
}
}
.navbar {
background-color: rgb(188 174 159);
font-family: source-serif-pro, serif;
font-weight: 700;
font-style: normal;
border-bottom: 3px solid white;
font-size: 22px;
padding-bottom: 0.7vw;
padding-top: 0.7vw;
max-height: 9vh;
}
.navbar-brand img {
height: 7.5vh;
}
.navbar-nav {
display: flex;
justify-content: space-between;
width: 100%;
margin-left: 1rem;
}
.nav-item {
font-size: 2vw;
background-color: #e4dbd1 !important;
display: flex;
height: calc(9vh - 3px);
}
.nav-link {
color: #731d2c !important;
display: flex;
align-self: center;
}
.nav-link.active {
color: #94253d !important;
}
.nav-item:hover {
background-color: #e4dbd1 !important;
}
#media screen and (min-width: 992px) {
.nav-item {
font-size: 25px;
flex: 0 1 20%;
justify-content: center;
}
/*For hovering testing*/
.nav-item:hover {
background-color: red !important;
}
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<a class="navbar-brand" href="index.html"><img src="img/logo.svg"></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">
<li class="nav-item">
<a class="nav-link active" href="index.html">Map</a>
</li>
<li class="nav-item">
<a class="nav-link" href="timeline.html">Timeline</a>
</li>
<li class="nav-item">
<a class="nav-link" href="essays.html">Short Essays</a>
</li>
<li class="nav-item">
<a class="nav-link" href="bibliography.html">Bibliography</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
</ul>
</div>
</div>
</nav>
As for your case, you don't want to have them equally due to content length. I'd suggest that you should modify flex-grow in flex
#media screen and (min-width: 992px) {
.nav-item {
font-size: 25px;
flex: 2 1 auto; /*set flex-grow to 2 and flex-basis to auto*/
justify-content: center;
}
/*For hovering testing*/
.nav-item:hover {
background-color: red !important;
}
}
One side note is that on the bigger screen with enough space, the width size is distributed equally, but on the smaller screen, you will see that the width size will be distributed according to content length
.navbar {
background-color: rgb(188 174 159);
font-family: source-serif-pro, serif;
font-weight: 700;
font-style: normal;
border-bottom: 3px solid white;
font-size: 22px;
padding-bottom: 0.7vw;
padding-top: 0.7vw;
max-height: 9vh;
}
.navbar-brand img {
height: 7.5vh;
}
.navbar-nav {
display: flex;
justify-content: space-between;
width: 100%;
margin-left: 1rem;
}
.nav-item {
font-size: 2vw;
background-color: #e4dbd1 !important;
display: flex;
height: calc(9vh - 3px);
}
.nav-link {
color: #731d2c !important;
display: flex;
align-self: center;
}
.nav-link.active {
color: #94253d !important;
}
.nav-item:hover {
background-color: #e4dbd1 !important;
}
#media screen and (min-width: 992px) {
.nav-item {
font-size: 25px;
flex: 2 1 auto;
justify-content: center;
}
/*For hovering testing*/
.nav-item:hover {
background-color: red !important;
}
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container">
<a class="navbar-brand" href="index.html"><img src="img/logo.svg"></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">
<li class="nav-item">
<a class="nav-link active" href="index.html">Map</a>
</li>
<li class="nav-item">
<a class="nav-link" href="timeline.html">Timeline</a>
</li>
<li class="nav-item">
<a class="nav-link" href="essays.html">Short Essays</a>
</li>
<li class="nav-item">
<a class="nav-link" href="bibliography.html">Bibliography</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
</ul>
</div>
</div>
</nav>

Logo link in Responsive CSS Navbar not working

I am new to CSS and trying to enable a responsive centered/navbar menu to my page with a logo positioned to left of navigation menu. Everything visually and functionally appears OK however the image logo link is not working (will not hyperlink) and I cannot figure out why. Any help or guidance to what I might be missing? Thanks so much in advancce. Here is my HTML/CSS.
<nav class="navbar navbar-default">
<div class="container">
<a class="navbar-brand" href="https://www.mytestorganization.com">
<img src="/logo/content/items/925f35a5b1cb48379a2e2c416b4f03e4/data"
width="120" alt="myOrgLogo" />
</a>
<!-- This is optional and can be removed. -->
<div class="container-fluid">
<!-- This is what generates your burger menu icon on mobile -->
<div class="navbar-header">
<button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> </button>
</div>
<!-- This is what gets hidden behind the burger menu icon -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
Nav1
<ul class="dropdown-menu">
<li>
Menu1
</li>
</ul>
</li>
<li class="dropdown">
Nav2
<ul class="dropdown-menu">
<li>
menu2
</li>
</ul>
</li>
<li class="dropdown">
Nav3
<ul class="dropdown-menu">
<li>
menu3
</li>
</ul>
</li>
<li class="dropdown">
nav4
<ul class="dropdown-menu">
<li>
Menu4
</li>
</ul>
</li>
<li class="dropdown">
nav5
<ul class="dropdown-menu">
<li>
menu5
</li>
</ul>
</li>
<li class="dropdown">
nav6
<ul class="dropdown-menu">
<li>
menu6
</li>
</ul>
</li>
<li class="dropdown">
nav7
<ul class="dropdown-menu">
<li>
Menu7
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
</div>
<!-- /.container-fluid -->
</nav>
.navbar-brand {
float: left;
padding:0;
padding-left: 0px;
}
.navbar{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
}
.navbar-nav {
position: absolute;
left: 0%;
top: 0%;
right: 0%;
bottom: 0%;
z-index: 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
#media screen and (max-width: 768px) {
.header-container .navbar-header {
width: 100%;
}
.navbar-default .navbar-toggle {
margin-top: 18px;
}
.navbar .container-fluid {
display: block !important;
}
.navbar.navbar-default .navbar-collapse.collapse {
overflow: hidden;
display: none !important;
}
.navbar.navbar-default .navbar-collapse.collapse.in {
display: block !important;
}
.navbar.navbar-default .navbar-nav {
display: inherit;
padding: 0 0 1rem 0;
}
.navbar.navbar-default .navbar-nav > li {
display: block;
}
}
the link in href="https://www.mytestorganization.com" is not working. There is no webpage with this url. But if you are looking for a cursor change when you hover over your logo or click on logo image then you can apply this style.
.navbar-brand {
float: left;
padding:0;
padding-left: 0px;
cursor:pointer;
}
.navbar-brand:hover{
cursor:pointer;
}

Setting margin to auto in a flexbox

I was following along the tutorial on youtube link and I got stuck in this part that's using margin-top: auto in a flexbox to push the last child to bottom. Can you please point out what's not working here?
.navbar {
width: 5rem;
height: 100vh;
position: fixed;
background-color: var(--bg-primary);
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.nav-item:last-child {
margin-top: auto;
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
</ul>
</nav>
This works as expected, the last <li> is pushed to the bottom of the parent, but since the parent (.navbar-nav) has the same height, you don't see the element moving.
Increasing the .navbar-nav height will enable the <li> to move down:
.navbar-nav {
...
height: 100vh;
}
.navbar {
width: 5rem;
height: 100vh;
position: fixed;
background-color: var(--bg-primary);
}
.navbar-nav {
height: 100vh;
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.nav-item:last-child {
margin-top: auto;
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
</ul>
</nav>
you should add height: 100%; either
.navbar {
width: 5rem;
height: 100%;
position: fixed;
background-color: var(--bg-primary);
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height:100%;
}
.nav-item:last-child {
margin-top: auto;
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
</ul>
</nav>
After setting the height of 100vh to .navbar-nav, you can use flex:1 on 2nd child to make sure it takes the free space around. This will automatically push the last child to the bottom. In this case you even don't need to bother about using margin's to place elements inside the flex-container at different positions. flexbox properties and flex-item properties takes care of positioning our flex-items.
Code Modifications:
.navbar-nav{
height:100vh;
}
.nav-item:nth-child(2) {
flex:1;
}
.navbar {
width: 5rem;
height: 100vh;
position: fixed;
background-color: teal;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height:98vh;
}
.nav-item:nth-child(2) {
flex:1;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" >
<span class="link-text">Cats</span>
</a>
</li>
</ul>
</nav>
</body>
</html>
Note: The fundamental issue with margin-top not working is already covered in the above answers. Obviously the height issue with flex-container .navbar-nav div

Bootstrap 4 hover on navbar links causes flickering

I want to make my navbar links have a darker background color whenever I hover my mouse over them. It is working OK, but when I change padding (to 0px in this case) it starts to flicker: (View on full screen for better effect)
Also, the image link is not the same height as the other links(And when collapsed, it has this right blank space), and I can't get it in same line using the current styling rules.
**Edit: It's caused by the padding:0px!important, but that's because I do not want the hovering background to take the entire height. How to make the hovering background with less height?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.navbar {
min-height: 80px;
font-size: 0.8rem;
font-weight:500;
}
.navbar-brand {
padding: 0 15px;
height: 80px;
line-height: 80px;
}
.navbar-toggle {
/* (80px - button height 34px) / 2 = 23px */
margin-top: 23px;
padding: 9px 10px !important;
}
#media (min-width: 768px) {
.navbar-nav > li > a {
/* (80px - line-height of 27px) / 2 = 26.5px */
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
.bottom-space {
margin-bottom: 20px;
}
#navbar_logged_in > a:link {
color: white ;
}
#navbar_logged_in > a:hover {
opacity:0.7 ;
}
#navbar_logged_in > a:visited {
color: white ;
}
#navbar_logged_in > li.nav-link{
color:white;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link{
background-color: #17A2B8;
}
body {
padding-top: 110px;
}
.main-nav a:hover {
background-color: #0D47A1!important;
padding: 0px!important;
}
</style>
<nav id="navbar_logged_in" class="navbar navbar-expand-lg navbar-light bottom-space fixed-top" style="background: linear-gradient(to right, #3399ff , #1a8cff, #0080ff, #0073e6);">
<div class="container">
<a class="navbar-brand mx-auto" href="#">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white;margin-right:25px;">
<img class="img-circle" src="Image" alt="Image" width="35" height="35" style="border-radius: 50%!important;">
</a>
</li>
<li class="nav-item main-nav">
<a id="homepage_link" class="nav-link" href="#" style="color:white">Homepage</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">About</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">Log Out</a>
</li>
</ul>
</div>
</div>
</nav>
What's causing that? How can I fix it?
Thanks
The flickering is caused because when you hover, you are removing the padding, which pulls the element out from under the cursor. This then stops the hover and reapplies the padding which puts it back under the cursor, triggering the hover state. Rinse and repeat.
To stop the flicker, you need these two styles to work together:
#media (min-width: 768px) {
.navbar-nav > li > a {
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
.main-nav a:hover {
background-color: #0D47A1!important;
padding: 0px!important;
}
If you want the hovering background to take less height, replace the part that you don't want the background on with margin. This might look like:
#media (min-width: 768px) {
.navbar-nav > li > a {
padding: 6.5px 8px; /* top/bottom, sides */
margin: 20px 0px;
line-height: 27px;
}
}
.main-nav a:hover {
background-color: #0D47A1!important;
}
In short, don't make your box size change on hover, and if you don't want background, use margin instead of padding
The padding in the hover is causing the problem: padding: 10px!important;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.navbar {
min-height: 80px;
font-size: 0.8rem;
font-weight:500;
}
.navbar-brand {
padding: 0 15px;
height: 80px;
line-height: 80px;
}
.navbar-toggle {
/* (80px - button height 34px) / 2 = 23px */
margin-top: 23px;
padding: 9px 10px !important;
}
#media (min-width: 768px) {
.navbar-nav > li > a {
/* (80px - line-height of 27px) / 2 = 26.5px */
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
.bottom-space {
margin-bottom: 20px;
}
#navbar_logged_in > a:link {
color: white ;
}
#navbar_logged_in > a:hover {
opacity:0.7 ;
}
#navbar_logged_in > a:visited {
color: white ;
}
#navbar_logged_in > li.nav-link{
color:white;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link{
background-color: #17A2B8;
}
body {
padding-top: 110px;
}
.main-nav a:hover {
background-color: #0D47A1!important;
}
</style>
<nav id="navbar_logged_in" class="navbar navbar-expand-lg navbar-light bottom-space fixed-top" style="background: linear-gradient(to right, #3399ff , #1a8cff, #0080ff, #0073e6);">
<div class="container">
<a class="navbar-brand mx-auto" href="#">
Logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white;margin-right:25px;">
<img class="img-circle" src="Image" alt="Image" width="35" height="35" style="border-radius: 50%!important;">
</a>
</li>
<li class="nav-item main-nav">
<a id="homepage_link" class="nav-link" href="#" style="color:white">Homepage</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">About</a>
</li>
<li class="nav-item main-nav">
<a class="nav-link" href="#" style="color:white">Log Out</a>
</li>
</ul>
</div>
</div>
</nav>

Flexbox css unordered list custom styling

I want to style my unordered list like this one below
Link to what i want to achive
My structure looks like:
<div class="tabs">
<ul class="tabs__labels">
<li class="0">
<a class="active" href="#">
<img/>
<div>something</div>
</a>
</li>
<li class="1">
<a class="" href="#">
<img/>
<div>something1</div>
</a>
</li>
...
</ul>
</div>
Is it a good idea to name the list classes like 0,1 etc. and style them separately to somehow achive this effect? How to use flexbox to get similar effect? Should i group them into rows?
Would this be a start?
.tabs__labels {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.tabs__labels li {
flex-basis: 45%;
margin: 20px 0;
padding: 0;
}
.tabs__labels li:nth-child(odd) {
display: flex;
justify-content: flex-end;
}
.tabs__labels li:nth-child(even) {
display: flex;
}
.tabs__labels li:nth-child(3),
.tabs__labels li:nth-child(4) {
flex-basis: 35%;
}
.tabs__labels li a {
display: flex;
justify-content: center;
align-items: center;
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid red;
text-decoration: none;
}
.tabs__labels li:nth-child(1)::before {
content: 'some text';
text-decoration: underline;
margin-right: 10px;
}
.tabs__labels li:nth-child(2)::after {
content: 'some text';
text-decoration: underline;
margin-left: 10px;
}
<div class="tabs">
<ul class="tabs__labels">
<li>
<a class="active" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
</ul>
</div>

Resources