How to dynamically change css content for navbar links - html

Right Now this is my homepage:
I used css content to show the link texts when the user hovers over the icons. However, right now whichever icon you hover over, it will show the same text "home". My question is how can I set different text outputs for each icon/link . Thank you in advance.
Navbar.html:
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo">
<img src="{% static 'portfolio/logo.png' %}" alt="">
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-home "></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-cog"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-book"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-tasks"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link">
<i class="fas fa-phone"></i>
</a>
</li>
</ul>
</nav>
_sidebar.scss:
.navbar{
position:fixed;
background-color: $navbg;
}
.navbar-nav{
list-style: none;
padding: 0;
margin: 0;
display:flex;
flex-direction: column;
align-items:center;
height: 100%;
}
.nav-item{
width:100%;
&:last-child {
margin-top: auto;
}
}
.nav-link{
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 5rem;
font-size: 2rem;
padding:1.5rem;
text-decoration: none;
i{
font-size: 3rem;
color: $navicon;
&:hover{
color:$icon-hover;
}
}
&:hover::after{
content : "Home";
position: absolute;
color:#12181b;
background: #b2becd;
right:-7rem;
border-radius: 0.5rem;
padding:0.5rem;
margin-left:2rem;
}
}
.logo{
display: flex;
align-items: center;
justify-content: center;
margin-top: 2rem;
margin-bottom: 2.5rem;
width: 100%;
img{
width:60%;
}
}

Using content isn't the correct way to add dynamic contents, that to to a compiled SCSS. You need to add another element, keep it hidden normally and show it when user hovers over it's parent.
This way you can add proper content for each icon whether statically or dynamically, following is a proof of concept:
.navbar {
position: fixed;
background-color: black;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.nav-item {
width: 100%;
}
.nav-item:last-child {
margin-top: auto;
}
.nav-link {
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 5rem;
font-size: 2rem;
padding: 1.5rem;
text-decoration: none;
}
.nav-link i {
font-size: 3rem;
color: white;
}
.nav-link i:hover {
color: red;
}
.label {
display: none;
}
.nav-item:hover .label {
display: block;
position: absolute;
color: #12181b;
background: #b2becd;
right: -7rem;
border-radius: 0.5rem;
padding: 0.5rem;
margin-left: 2rem;
}
.logo {
display: flex;
align-items: center;
justify-content: center;
margin-top: 2rem;
margin-bottom: 2.5rem;
width: 100%;
}
.logo img {
width: 60%;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo"><img src="{% static 'portfolio/logo.png' %}" alt="">
</li>
<li class="nav-item">
<i class="fas fa-home "></i><span class="label">First Icon</span></li>
<li class="nav-item"><i class="fas fa-cog"></i><span class="label">Second Icon</span></li>
<li class="nav-item"><i class="fas fa-book"></i><span class="label">Third Icon</span></li>
<li class="nav-item"><i class="fas fa-tasks"></i><span class="label">fourth Icon</span></li>
<li class="nav-item"><i class="fas fa-phone"></i><span class="label">Fifth Icon</span></li>
</ul>
</nav>

You can use data attribute in html and call it from css for diffrent content values
// HTML
<li class="nav-item">
<a href="" class="nav-link" data-title="home">
<i class="fas fa-home"></i>
</a>
</li>
<li class="nav-item">
<a href="" class="nav-link" data-title="setting">
<i class="fas fa-cog"></i>
</a>
</li>
...
// CSS
.nav-link:hover::after {
content: attr(data-title); // added
position: absolute;
color: #12181b;
background: #b2becd;
right: -7rem;
border-radius: 0.5rem;
padding: 0.5rem;
margin-left: 2rem;
}

Related

unable to move last child of my nav bar to the bottom of the navbar

Unable to move my GitHub icon/link to the bottom of the navbar. I'm trying to use the last-child margin-top auto however it won't work for me. is there something wrong in my code, or am I going about it the wrong way? any advice would be great. I'm new to HTML and CSS so if you see anything you would change in general please let me know.
:root {
font-size: 16px;
font-family: 'Open sans';
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
color: white;
background-color: black;
}
body::-webkit-scrollbar {
width: 0.3rem;
}
body::-webkit-scrollbar-track {
background-color: red;
}
body::-webkit-scrollbar-thumb {
background-color: blueviolet;
}
main {
margin-left: 15rem;
padding: 1rem;
}
/****** Navbar ******/
.img-logo {
width: 15rem;
margin-top: 1rem;
}
.navbar {
position: fixed;
background-color: blueviolet;
width: 15rem;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
}
.nav-item:last-child {
margin-top: auto;
}
<body>
<div class="navbar">
<nav>
<img class="img-logo" src="img/Logo.png" alt="My logo">
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-house"></i>
<span class="link-text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-user"></i>
<span class="link-text">About Me</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-screwdriver-wrench"></i>
<span class="link-text">What I Do</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-folder-open"></i>
<span class="link-text">Projects</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-id-card"></i>
<span class="link-text">Contact</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-brands fa-github"></i>
<span class="link-text"></span>
</a>
</li>
</ul>
</nav>
</div>
I got it working by flexing the navbar (parent of both navbar-nav and your image):
:root {
font-size: 16px;
font-family: 'Open sans';
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
color: white;
background-color: black;
}
body::-webkit-scrollbar {
width: 0.3rem;
}
body::-webkit-scrollbar-track {
background-color: red;
}
body::-webkit-scrollbar-thumb {
background-color: blueviolet;
}
main {
margin-left: 15rem;
padding: 1rem;
}
/****** Navbar ******/
.img-logo {
width: 15rem;
margin-top: 1rem;
order: 2;
}
nav {
display: flex;
flex-flow: column nowrap;
position: fixed;
background-color: blueviolet;
width: 15rem;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
}
.nav-item:last-child {
margin-top: auto;
}
<body>
<nav>
<img class="img-logo" src="img/Logo.png" alt="My logo">
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-house"></i>
<span class="link-text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-user"></i>
<span class="link-text">About Me</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-screwdriver-wrench"></i>
<span class="link-text">What I Do</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-folder-open"></i>
<span class="link-text">Projects</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-id-card"></i>
<span class="link-text">Contact</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-brands fa-github"></i>
<span class="link-text"></span>
</a>
</li>
</ul>
</nav>
You already have a flexbox for your nav items so it makes sense to just add the logo as a list item. For this example, I called it .logo. You can then take this new list item and nest the image within. Next, we'll flex this new list item and use flex-basis: 100%;. Then you can specify align-items: flex-end; for it to be at the very bottom of the navbar.
From here, you can specify margin-left: auto; for it to be aligned to the right or the opposite for it to be aligned on the left.
:root {
font-size: 16px;
font-family: 'Open sans';
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
color: white;
background-color: black;
}
body::-webkit-scrollbar {
width: 0.3rem;
}
body::-webkit-scrollbar-track {
background-color: red;
}
body::-webkit-scrollbar-thumb {
background-color: blueviolet;
}
main {
margin-left: 15rem;
padding: 1rem;
}
/****** Navbar ******/
.img-logo {
margin-top: 1rem;
}
.navbar {
position: fixed;
background-color: blueviolet;
width: 15rem;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
}
.nav-item:last-child {
margin-top: auto;
}
.logo {
display: flex;
flex-basis: 100%;
align-items: flex-end;
}
<body>
<div class="navbar">
<nav>
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-house"></i>
<span class="link-text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-user"></i>
<span class="link-text">About Me</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-screwdriver-wrench"></i>
<span class="link-text">What I Do</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-folder-open"></i>
<span class="link-text">Projects</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-id-card"></i>
<span class="link-text">Contact</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-brands fa-github"></i>
<span class="link-text"></span>
</a>
</li>
<li class="logo">
<img class="img-logo" src="https://dummyimage.com/75/000/fff" alt="My logo">
</li>
</ul>
</nav>
</div>

Menu item active for master header page

I have sticky left nav bar, I would like to active nav as per page, I did class active for related page nav items but now I moved to header single one master page now I added active class in any nav item the only one active nav shows whatever page I am is on. I need active item as per page nav, please help.
.navbar {
position: fixed;
background-color: #C8E8E9;
transition: width 600ms ease;
overflow: hidden;
z-index:9;
border-radius:0px!important;
top: 0;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
width: max-content;
font-family: 'Open Sans';
}
.nav-item {
width: 100%;
}
.nav-item a {
}
.nav-item .active {
background-color: #ffc20e!important;
}
.nav-item:last-child {
margin-top: auto;
}
.active-nav{
background-color:#FFDB72;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
color: #000000;
text-decoration: none;
/*filter: grayscale(100%) opacity(0.7);*/
transition: var(--transition-speed);
}
.nav-link:hover {
filter: grayscale(0%) opacity(1);
background: #FFDB72;
color: #000000;
}
.link-text {
display: none;
margin-left: 0rem;
padding-left: 21px;
font-size: 13px;
font-weight: 600;
margin-right:50px;
}
.nav-link-arrow{
width: 2rem;
min-width: 2rem;
margin: 0 1.5rem;
}
.nav-link-icon{
width: 0rem;
min-width:0rem;
margin: 0 1.5rem;
}
.nav-link svg {
width: 1rem;
min-width: 1rem;
margin: 0 1.5rem;
}
.fa-primary {
color: #ff7eee;
}
.fa-secondary {
color: #df49a6;
}
.fa-primary,
.fa-secondary {
transition: var(--transition-speed);
}
.logo {
font-weight: bold;
text-transform: uppercase;
margin-bottom: 1rem;
text-align: center;
font-size: 1.5rem;
letter-spacing: 0.3ch;
width: 100%;
}
.logo svg {
transform: rotate(0deg);
transition: var(--transition-speed);
filter: brightness(0.2) sepia(1) hue-rotate(180deg) saturate(5);
}
.logo-text
{
display: inline;
position: absolute;
left: -999px;
transition: var(--transition-speed);
font-size:16px;
}
.navbar:hover .logo svg {
transform: rotate(-180deg);
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo">
<a href="#" class="nav-link">
<span class="link-text logo-text">Menu</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-university nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 1</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-book nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 2</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-user nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 3</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-picture-o nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 4</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link pl-25">
<img src="images/image.png">
<span class="link-text">Nav 5</span>
</a>
</li>
</ul>
</nav>
Here i don't understand your question but here i understand a little bit what you want is nav active when clicked on one page, sorry if i misunderstood
Here I try my best to help and hope it helps
Here I added Jquery, you can try it
$(function(){
$('.navbar-nav a').on("click",function(){
$('.nav-link').removeClass('active');
$(this).addClass('active');
});
})
.navbar {
position: fixed;
background-color: #C8E8E9;
transition: width 600ms ease;
overflow: hidden;
z-index:9;
border-radius:0px!important;
top: 0;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
width: max-content;
font-family: 'Open Sans';
}
.nav-item {
width: 100%;
}
.nav-item a {
}
.nav-item .active {
background-color: #ffc20e!important;
}
.nav-item:last-child {
margin-top: auto;
}
.active-nav{
background-color:#FFDB72;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
color: #000000;
text-decoration: none;
/*filter: grayscale(100%) opacity(0.7);*/
transition: var(--transition-speed);
}
.nav-link:hover {
filter: grayscale(0%) opacity(1);
background: #FFDB72;
color: #000000;
}
.link-text {
display: none;
margin-left: 0rem;
padding-left: 21px;
font-size: 13px;
font-weight: 600;
margin-right:50px;
}
.nav-link-arrow{
width: 2rem;
min-width: 2rem;
margin: 0 1.5rem;
}
.nav-link-icon{
width: 0rem;
min-width:0rem;
margin: 0 1.5rem;
}
.nav-link svg {
width: 1rem;
min-width: 1rem;
margin: 0 1.5rem;
}
.fa-primary {
color: #ff7eee;
}
.fa-secondary {
color: #df49a6;
}
.fa-primary,
.fa-secondary {
transition: var(--transition-speed);
}
.logo {
font-weight: bold;
text-transform: uppercase;
margin-bottom: 1rem;
text-align: center;
font-size: 1.5rem;
letter-spacing: 0.3ch;
width: 100%;
}
.logo svg {
transform: rotate(0deg);
transition: var(--transition-speed);
filter: brightness(0.2) sepia(1) hue-rotate(180deg) saturate(5);
}
.logo-text
{
display: inline;
position: absolute;
left: -999px;
transition: var(--transition-speed);
font-size:16px;
}
.navbar:hover .logo svg {
transform: rotate(-180deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar">
<ul class="navbar-nav">
<li class="logo">
<a href="#" class="nav-link">
<span class="link-text logo-text">Menu</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link active">
<i class="fa fa-university nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text ">Nav 1</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-book nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 2</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-user nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 3</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa fa-picture-o nav-link-icon fa-lg" aria-hidden="true"></i>
<span class="link-text">Nav 4</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link pl-25">
<img src="images/image.png">
<span class="link-text">Nav 5</span>
</a>
</li>
</ul>
</nav>

Trying to recreate this template, but the menu is not working as I want it to?

I'm trying to make my menu look like the one on this page.
But somehow it's not working. This is my website so far. My main pet peeves with this is the menu items are not centered and the social media icons are nowhere to be seen.
Not only that, but even though I have the same thing written in every page (I copy-pasted everything), the home page is the only one that's listening to the CSS.
This is my code so far:
body {
background-color: #202020 !important;
font-family: "Open Sans", sans-serif;
}
#header {
background-color: #202020;
text-align: center;
margin: 5px auto;
padding: 2px 0px;
}
.navbar {
display: flex;
justify-content: flex-end;
color: #f8f8f8;
background-color: #202020;
height: fit-content;
}
.nav-link {
flex: 1 1 auto;
padding: 5px 0;
color: #f8f8f8;
background-color: #202020;
text-align: center;
display: inline-block;
text-decoration: none;
width: -moz-fit-content;
transition: 0.2s;
}
.nav-link:hover {
background-color: #f8f8f8;
color: #202020;
}
.navbar {
position: relative;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.navbar li {
position: relative;
padding: 10px 0 10px 28px;
text-decoration: none;
list-style-type: none;
display: flex;
justify-content: end;
}
.navbar a {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 15px;
white-space: nowrap;
transition: 0.3s;
position: relative;
text-align: center;
flex-wrap: wrap;
align-items: center;
}
a {
text-decoration: none;
color: #f8f8f8;
}
.navbar-brand {
text-decoration: none;
color: #f8f8f8;
font-size: 20px;
padding: 5px;
}
.navbar-brand:hover {
text-decoration: none;
color: #202020;
background-color: #f8f8f8;
padding: 5px;
}
.header-social-links a {
line-height: 0px;
font-size: 16px;
}
.navbar-dark .navbar-toggler {
color: #f8f8f8;
border-color: #f8f8f8;
background-color: #202020;
}
#name {
font-size: 20px;
}
<body cz-shortcut-listen="true">
<header id="header" class="fixed-top">
<nav class="navbar navbar-expand-lg fixed-top navbar order-last order-lg-0">
<div class="container-fluid d-flex justify-content-between align-items-center">
<a class="navbar-brand" href="index.html" id="name">Maria F. Loscher</a>
<button class="navbar-dark navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html">about me</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/portfolio.html">portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/cv.html">curriculum vitae</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/commissions-hiring.html">commissions' pricing and hiring info</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html#contact">contact</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="header-social-links">
<i class="bi bi-twitter"></i>
<i class="bi bi-facebook"></i>
<i class="bi bi-instagram"></i>
<i class="bi bi-linkedin"></i>
</div>
</header>
</body>
This worked for me:
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Maria F. Loscher</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
</head>
<style>
.body {
background-color: #202020 !important;
font-family: "Open Sans", sans-serif;
}
#header {
background-color: #202020;
text-align: center;
margin: 5px auto;
}
.navbar {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
position: relative;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.nav-link {
flex: 1 1 auto;
padding: 5px 0;
color: #f8f8f8;
background-color: #202020;
text-align: center;
display: inline-block;
text-decoration: none;
width: -moz-fit-content;
transition: 0.2s;
}
.nav-link:hover {
background-color: #f8f8f8;
color: #202020;
}
.navbar li {
position: relative;
padding: 10px 0 10px 28px;
text-decoration: none;
list-style-type: none;
display: flex;
justify-content: end;
}
.navbar a {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 15px;
white-space: nowrap;
transition: 0.3s;
position: relative;
text-align: center;
flex-wrap: wrap;
align-items: center;
}
a {
text-decoration: none;
color: #f8f8f8;
}
.navbar-brand {
text-decoration: none;
color: #f8f8f8;
font-size: 20px;
}
.navbar-brand:hover {
text-decoration: none;
color: #202020;
background-color: #f8f8f8;
}
.header-social-links a {
line-height: 0px;
font-size: 16px;
}
.navbar-dark .navbar-toggler {
color: #f8f8f8;
border-color:#f8f8f8;
background-color: #202020;
}
#name {
font-size: 20px;
}
</style>
<body cz-shortcut-listen="true">
<header id="header" class="fixed-top">
<nav class="navbar navbar-expand-lg fixed-top navbar order-last order-lg-0">
<div class="container-fluid d-flex justify-content-between align-items-center">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<a class="navbar-brand" href="index.html" id="name">Maria F. Loscher</a>
<button class="navbar-dark navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html">about me</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/portfolio.html">portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/cv.html">curriculum vitae</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/commissions-hiring.html">commissions' pricing and hiring info</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/about.html#contact">contact</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="header-social-links">
<i class="bi bi-twitter"></i>
<i class="bi bi-facebook"></i>
<i class="bi bi-instagram"></i>
<i class="bi bi-linkedin"></i>
</div>
</header>
</body>
I throw your navbar in the same div as the navitems
I added some css code for the navbar from here:https://www.w3schools.com/howto/howto_js_topnav.asp

Adding a social nav bar above my main nav bar

I am trying to get my social nav-bar to sit above my main nav bar which I have achieved but the issue I now face is that the main content of the page overlaps the nav bar.
If i add padding to the body it just makes the nav bar move down the page.
I can't for the life of me find what the issue is.. sorry i am learning at the moment so please don't be too harsh. any help would be appreciated.
body {
padding: 50px;
}
.topnav {
text-align: right;
font-family: 'Quicksand', sans-serif;
background: #f4f5eb;
padding: 0 20px;
margin: 0;
overflow: hidden;
}
.social li {
text-align: right;
list-style: none;
display: inline-block;
}
a {
text-decoration: none;
padding: 0 10px;
color: grey;
font-size: 15px;
}
a:hover {
color: rgb(17, 240, 17);
}
.social1 {
font-size: 10px;
color: black;
padding: 5px;
}
.main-nav {
text-align: center;
font-family: 'Quicksand', sans-serif;
padding: 0 40px;
margin: 0;
overflow: hidden;
padding: 15px;
float: left;
}
.main li {
text-align: center;
list-style: none;
display: inline-block;
}
.main1 {
color: black;
}
#logo {
float: left;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 7 !important;
}
.dropdown-content a {
color: grey;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1;
color: rgb(17, 240, 17);
}
.dropdown:hover .dropdown-content {
display: block;
}
<header>
<nav class="topnav">
<div class="topnav-social">
<ul class="social">
<li>Social Wall</li>
<li>
<a href="https://www.egis-group.com/rss.xml" i class="fas fa-rss"></i>
</a>
</li>
<li>
<a href="https://vimeo.com/channels/egis" i class="fab fa-vimeo-v"></i>
</a>
</li>
<li>
<a href="https://www.youtube.com/channel/UC7htuNSYHgMDr5wkoQMD8lQ" i class="fab fa-youtube"></i>
</a>
</li>
<li>
<a href="https://twitter.com/egis" i class="fab fa-twitter"></i>
</a>
</li>
<li>
<a href="http://www.linkedin.com/company/egis" i class="fab fa-linkedin-in"></i>
</a>
</li>
<li>
<a href="http://fr.viadeo.com/fr/company/egis?gaid=2012012300803" i class="fab fa-viadeo"></i>
</a>
</li>
<li>
<a href="https://www.facebook.com/egisgroup" i class="fab fa-facebook-f"></i>
</a>
</li>
<li><a class="social1" href="https://www.egis-group.com/talent/join-us" target="_blank">Join Us</a></li>
<li><a class="social1" href="https://www.egis-group.com/contact" target="_blank">Contact</a></li>
<li><a class="social1" href="https://www.egis-group.com/publications" target="_blank">Publications</a></li>
</ul>
</div>
</nav>
<div id=logo>
<img src="images/logo.jpg" width="350" height="100" alt="Brand">
</div>
<nav class="main-nav">
<div class="mainnav-head">
<ul class="main">
<li><a class="main1" href="index.php">Home</a></li>
<?php if((isset($_SESSION['username']) || isCookieValid($db))): ?>
<li>my profile</li>
<li class="dropdown">
Skills By Shift
<div class="dropdown-content">
Traffic Management
Lead Installers/Fiss
Licenses
Other Skills
</div>
</li>
<li class="dropdown">
Risk Assessments/Method Statements
<div class="dropdown-content">
Traffic Management
VSF/Barrier
C'way Repairs
Equiptment
</div>
</li>
<li>Logout</li>
<?php else: ?>
<li><a class="main1" href="">Blog</a></li>
<li><a class="main1" href="">About</a></li>
<li><a class="main1" href="">Egis Projects</a></li>
<li><a class="main1" href="login.php">Login</a></li>
<?php endif ?>
</ul>
</div>
</nav>
</header>
You can achieve this with flexbox.
<div class="full-nav-wrapper">
<div class="social-nav-wrapper">
<div class="social-nav-left">
Social Wall
</div>
<div class="social-nav-right">
Join Us
Contact
Publications
</div>
</div>
<div class="main-nav-wrapper">
<div class="main-nav-logo">
<img src="https://via.placeholder.com/140x100">
</div>
<div class="main-nav-links">
Home
My Profile
Skills By Shift
Risk Assessments/Method Statements
Logout
Blog
About
Egis
Projects
Login
</div>
</div>
</div>
CSS
a {
color:white;
}
.full-nav-wrapper {
border:2px solid purple;
}
.social-nav-wrapper {
background-color:blue;
display:flex;
justify-content: space-between;
}
.social-nav-left {
}
.social-nav-right {
}
.main-nav-wrapper {
background-color:pink;
display:flex;
justify-content: space-between;
align-items:center;
}
.main-nav-logo {
display:flex;
flex-grow: 1;
}
.main-nav-logo > img {
width: 50px;
height: 50px;
}
.main-nav-links {
display:flex;
justify-content: space-around;
flex-grow:3;
}
That's a lot of links though so you would need to work in a responsive technique for proper display on mobile.
#media (max-width:767px) {
.main-nav-wrapper {
flex-wrap: wrap;
}
.main-nav-links {
display: flex;
justify-content: space-around;
}
.main-nav-logo {
justify-content: center;
}
.main-nav-links {
flex-wrap: wrap;
}
}
I think this is what you want to achieve though.
I colored the divs so you can go back and possibly understand what I did.
Learn up on flexbox if you find this code somewhat understandable.
Codepen: https://codepen.io/nolaandy/pen/OqarXY

Position font awesome span icon above text within an anchor

I'm trying to make some buttons with text positioned below a font awesome icon where both are positioned centrally inside a list item, and I need the anchor element, which also contains the span element for the font awesome icon, to fill the entire size of the list item.
I can fill the list item with the anchor no problem, but I'm having trouble positioning the icon's span above the text in the anchor that contains it.
JSFiddle: https://jsfiddle.net/qod142fz/.
HTML:
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><span class="fa fa-home"></span>Home</li>
<li class="navButton"><span class="fa fa-user"></span>Personal Details</li>
<li class="navButton"><span class="fa fa-briefcase"></span>Company</li>
<li class="navButton"><span class="fa fa-gbp"></span>Invoices</li>
<li class="navButton"><span class="fa fa-address-book"></span>Contacts</li>
<li class="navButton"><span class="fa fa-minus"></span>Expenses</li>
<li class="navButton"><span class="fa fa-list"></span>Payslips</li>
<li class="navButton"><span class="fa fa-cog"></span>Settings</li>
</ul>
</div>
CSS:
/* SIDEBAR PRIMARY */
#sidebarPrimary
{
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary > ul
{
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary > ul > li.navButton
{
width: 100%;
height: 15vw;
}
#sidebarPrimary > ul > li.navButton > a
{
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary > ul > li.navButton > a:hover
{
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary > ul > li.navButton > a > span
{
display: block;
text-align: center;
margin-bottom: 5px;
}
Problem is coming from flex. I recommend wrapping another div around the elements that should be centered inside the a tags
/* SIDEBAR PRIMARY */
#sidebarPrimary {
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary > ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary > ul > li.navButton {
width: 100%;
height: 15vw;
}
#sidebarPrimary > ul > li.navButton > a {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
text-decoration: none;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary > ul > li.navButton > a:hover {
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary > ul > li.navButton > a .fa {
display: block;
height: 1em;
margin: 0 auto 5px;
text-align: center;
width: 1em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-home"></span>Home
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-user"></span>Personal Details
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-briefcase"></span>Company
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-gbp"></span>Invoices
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-address-book"></span>Contacts
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-minus"></span>Expenses
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-list"></span>Payslips
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-cog"></span>Settings
</div>
</a></li>
</ul>
</div>
#sidebarPrimary {
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary>ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary>ul>li.navButton {
width: 100%;
height: 15vw;
}
#sidebarPrimary>ul>li.navButton>a {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary>ul>li.navButton>a:hover {
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary>ul>li.navButton>a>span {
display: block;
text-align: center;
margin-bottom: 5px;
width: 20px;
height: 20px;
background-color: red;
position: absolute;
top: 10px;
}
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><span class="fa fa-home"></span>Home</li>
<li class="navButton"><span class="fa fa-user"></span>Personal Details</li>
<li class="navButton"><span class="fa fa-briefcase"></span>Company</li>
<li class="navButton"><span class="fa fa-gbp"></span>Invoices</li>
<li class="navButton"><span class="fa fa-address-book"></span>Contacts</li>
<li class="navButton"><span class="fa fa-minus"></span>Expenses</li>
<li class="navButton"><span class="fa fa-list"></span>Payslips</li>
<li class="navButton"><span class="fa fa-cog"></span>Settings</li>
</ul>
</div>
Just add position: absolute; top: 40px; to font-awesome icons