I am trying to nest a submenu in a main menu for a mobile navigation hamburger menu. Here is an image of what I am trying to achieve:
Right now, my submenus are appearing over my other menus and not embedding inside. I cannot figure what I am doing wrong. Any help would be greatly appreciated!
Here is a link to the codepen.io pin.
Here is the same code in codepen.io:
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#100;300;400;500;700;900&display=swap');
* {
font-family: 'Roboto', sans-serif;
}
.main-navigation-bar {
height: 94px;
background-color: #00000000;
display: flex;
}
.section-1 {
width: 30%;
display: flex;
align-items: center;
}
.logo-box {
width: 208px;
height: 48px;
}
.section-2 {
width: 70%;
justify-content: flex-end;
margin-left: auto;
margin-right: 0;
flex-wrap: wrap;
display: flex;
}
.main-nav {
list-style-type: none;
overflow: hidden;
display: block;
}
.main-nav li{
float: left;
padding: 10px 20px 10px 20px;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
font-style: normal;
text-decoration: none;
line-height: 24px;
letter-spacing: .75px;
color: #1e1e1e;
}
.main-nav li:hover {
color: #1e1e1e75;
cursor: pointer;
transition: .4s;
}
.dropdown-content {
display: none;
position: absolute;
z-index: 1;
transform: translateX(calc(-50%));
max-width: 1000px;
margin-top: 10px;
}
.dropdown:hover .dropdown-content {
display: block;
}
.sub-menu {
list-style-type:none;
overflow:hidden;
display: flex;
box-shadow: 0px 0px 2px 0px rgb(30 30 30 / 25%) !important;
z-index: 3px;
border-radius: 8px;
width: 100%;
}
.sub-menu li {
float: left;
padding: 24px 32px !important;
width: 100%;
}
.sub-menu li:hover {
cursor: pointer;
}
.item1 {
border-right: 1px solid #f2f2f2;
}
.product {
display: block;
font-size: 20px;
font-weight: 700px;
color: #1e1e1e;
}
.tagline {
display: block;
font-size: 14px;
font-weight: 400;
line-height: 24px;
letter-spacing: .44px;
text-transform: none;
color: #1e1e1e;
}
.g4-sub-tabs {
list-style: none;
text-align: left;
padding-left: 0px;
}
.g4-sub-tabs li {
margin: 0px !important;
padding: 0px !important;
}
.li-sub-tab {
padding-left: 25px;
}
#check, .open-menu, .close-menu {
display: none;
}
#media only screen and (max-width: 959px) {
.open-menu, .close-menu {
position: absolute;
color: #1e1e1e;
cursor: pointer;
font-size: 1.5rem;
}
.open-menu {
right: 20px;
transform: translateY(-50%);
}
.close-menu {
top: 20px;
right: 20px;
}
#check {
display: none;
}
.main-navigation-bar {
height: 100vh;
display: block;
}
.section-2 {
width: 100%;
}
.mobile-menu {
flex-direction: column;
align-items: center;
justify-content: center;
}
.mobile-menu li {
width: 100%;
top: 0;
right: 0;
z-index: 100;
transition: all 0.2s ease-in-out;
}
.dropdown-content {
display: block;
position: absolute;
z-index: 1;
transform: translateX(calc(0%));
max-width: auto;
margin-top: 10px;
}
.sub-menu {
list-style-type:none;
overflow:hidden;
display: block;
box-shadow: 0px 0px 2px 0px rgb(30 30 30 / 25%) !important;
z-index: 0px;
border-radius: 8px;
width: 100%;
}
.sub-menu li {
float: left;
padding: 24px 32px !important;
width: 100%;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<header>
<div class="main-navigation-bar">
<div class="section-1">
<div class="logo-box">
<h1>Logo</h1>
</div>
</div>
<input type="checkbox" id="check">
<div class="section-2">
<nav>
<ul class="main-nav">
<span class="mobile-menu">
<span class="dropdown">
<li>Products
<span class="sub-arrow">
<i class="fas fa-chevron-down"></i>
</span></span>
<span class="dropdown-content">
<ul class="sub-menu">
<li class="item1 "><span class="product">1A</span><p class="tagline">Lorem ipsum solor sal</p>
<ul class="g4-sub-tabs">
<li>•<span class="li-sub-tab">Link</span></li>
<li>•<span class="li-sub-tab">Link</span></li><li>•<span class="li-sub-tab">Link</span></li>
</ul>
</li>
<li class"item2"><span class="product">1B</span><p class="tagline">lorem ipsum dolor sal</p></li>
</ul>
</span>
</li>
<li>Resources</li>
<li>Company</li>
<li>Careers</li>
<li>Contact Us</li>
<label for="check" class="close-menu"><i class="fas fa-times"></i></label>
</span>
<label for="check" class="open-menu"><i class="fas fa-bars"></i></label>
</ul>
</nav>
</div>
</div>
</header>
Simply use the CSS display rule and toggle none.
if (document.getElementById("btn")) {
document.getElementById("btn").addEventListener("click", function (evt) {
toggleDisplay(evt);
});
}
function toggleDisplay(evt){
document.getElementById("first").classList.toggle("hidden");
}
.hidden {
display: none;
}
<header>
<div class="main-navigation-bar">
<button id="btn">toggle me</button>
<div class="section-1">
<div class="logo-box">
<h1>Logo</h1>
</div>
</div>
<div class="section-2">
<nav>
<ul class="main-nav">
<span class="mobile-menu">
<span class="dropdown">
<li>Products
<span class="sub-arrow">
<i class="fas fa-chevron-down"></i>
</span></span>
<span class="dropdown-content">
<ul class="hidden" id="first">
<li class="item1 "><span class="product">1A</span><p class="tagline">Lorem ipsum solor sal</p>
<ul class="g4-sub-tabs">
<li>•<span class="li-sub-tab">Link</span></li>
<li>•<span class="li-sub-tab">Link</span></li><li>•<span class="li-sub-tab">Link</span></li>
</ul>
</li>
<li class"item2"><span class="product">1B</span><p class="tagline">lorem ipsum dolor sal</p></li>
</ul>
</span>
</li>
<li>Resources</li>
<li>Company</li>
<li>Careers</li>
<li>Contact Us</li>
<label for="check" class="close-menu"><i class="fas fa-times"></i></label>
</span>
<label for="check" class="open-menu"><i class="fas fa-bars"></i></label>
</ul>
</nav>
</div>
</div>
</header>
Related
Hello I'm trying to style my navbar and have everything aligned properly, but I'm not sure what is making my nav content display like this. Also, how can I remove the grey box next to my nav brand? I messed around with it on the inspect elements, but I don't know how to get rid of it. I have provided my code below. Thanks!
When bs css link isn't added (How I want to keep it):
When bs css link is added:
HTML:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CodePen - Dashboard UI </title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<!---Navbar--->
<header>
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container-fluid">
<a style="font-size: 45px; color: #A388E7;" class="navbar-brand" href="#"><strong>StudioPick</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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 ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-curresnt="page" href="index.html">Home</a>
</li>
<li class="nav-item2">
<div class="action">
<div class="profile" onclick="menuToggle();">
<img src="./assets/avatar.jpg" />
</div>
<div class="menu">
<h3 id="profile-name"><strong>User Name</strong></h3>
<p class="text-muted" id="userType" style="position: relative; top: -20px; right: -60px; font-size: 12px !important">Studio</p>
<ul>
<li>
<img src="./assets/icons/user.png" />Dashboard
</li>
<li>
<img src="./assets/icons/edit.png" />Edit profile
</li>
<li>
<img src="./assets/icons/envelope.png" />Inbox
</li>
<li>
<img src="./assets/icons/settings.png" />Setting
</li>
<li><img src="./assets/icons/question.png" />Help</li>
<li>
<img src="./assets/icons/log-out.png" />Logout
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!---Navbar--->
<main class="main">
<div class="responsive-wrapper">
<div class="main-header">
<h1>Settings</h1>
<div class="search">
<input type="text" placeholder="Search" />
<button type="submit">
<i class="ph-magnifying-glass-bold"></i>
</button>
</div>
</div>
<div class="horizontal-tabs">
My details
Profile
Password
Team
Plan
Billing
Email
Notifications
Integrations
API
</div>
<div class="content-header">
<div class="content-header-intro">
<h2>Intergrations and connected apps</h2>
<p>Supercharge your workflow and connect the tool you use every day.</p>
</div>
<div class="content-header-actions">
<a href="#" class="button">
<i class="ph-faders-bold"></i>
<span>Filters</span>
</a>
<a href="#" class="button">
<i class="ph-plus-bold"></i>
<span>Request integration</span>
</a>
</div>
</div>
<div class="content">
<div class="content-panel">
<div class="vertical-tabs">
View all
Developer tools
Communication
Productivity
Browser tools
Marketplace
</div>
</div>
<div class="content-main">
<div class="card-grid">
<article class="card">
<div class="card-header">
<div>
<span><img src="https://assets.codepen.io/285131/zeplin.svg" /></span>
<h3>Zeplin</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Collaboration between designers and developers.</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
<article class="card">
<div class="card-header">
<div>
<span><img src="https://assets.codepen.io/285131/github.svg" /></span>
<h3>GitHub</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Link pull requests and automate workflows.</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
<article class="card">
<div class="card-header">
<div>
<span><img src="https://assets.codepen.io/285131/figma.svg" /></span>
<h3>Figma</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Embed file previews in projects.</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
</div>
</div>
</div>
</div>
</main>
<!-- partial -->
<script src='https://unpkg.com/phosphor-icons'></script><script src="./script.js"></script>
<script>
function menuToggle() {
const toggleMenu = document.querySelector(".menu");
toggleMenu.classList.toggle("active");
}
</script>
<!----More Bootstrap--->
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<!----More Bootstrap--->
</body>
</html>
CSS:
#import url("https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
:root {
--c-text-primary: #282a32;
--c-text-secondary: #686b87;
--c-text-action: #404089;
--c-accent-primary: #434ce8;
--c-border-primary: #eff1f6;
--c-background-primary: #ffffff;
--c-background-secondary: #fdfcff;
--c-background-tertiary: #ecf3fe;
--c-background-quaternary: #e9ecf4;
}
body {
line-height: 1.5;
min-height: 100vh;
font-family: "Be Vietnam Pro", sans-serif;
background-color: #E5E5E5 !important;
color: var(--c-text-primary);
}
:focus {
outline: 0;
}
.navbar-light {
background-color: #ffffff;
}
.navbar-nav{
justify-content: space-between;
}
.navbar-brand {
font-size: 45px;
color: #A388E7 !important;
font-weight: bolder;
padding-top: 0.3125rem;
padding-bottom: 0.3125rem;
margin-right: 1rem;
text-decoration: none;
white-space: nowrap;
}
.nav-item{
color: #686868 !important;
font-size: 20px;
position: relative;
right: -1675px !important;
}
.nav-item a {
display: block;
padding: 0.5rem 1rem;
color: #000000;
text-decoration: none;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out;
}
#alert{
position: relative;
right: -3px !important;
}
.action {
position: fixed;
top: 20px;
right: 30px;
}
.action .profile {
position: relative;
width: 60px;
height: 60px;
border-radius: 50%;
overflow: hidden;
cursor: pointer;
}
.action .profile img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.action .menu {
position: absolute;
top: 120px;
right: -10px;
padding: 10px 20px;
background: #fff;
width: 200px;
box-sizing: 0 5px 25px rgba(0, 0, 0, 0.1);
border-radius: 15px;
transition: 0.5s;
visibility: hidden;
opacity: 0;
}
.action .menu.active {
top: 80px;
visibility: visible;
opacity: 1;
}
.action .menu::before {
content: "";
position: absolute;
top: -5px;
right: 28px;
width: 20px;
height: 20px;
background: #fff;
transform: rotate(45deg);
}
*, ::after, ::before {
box-sizing: border-box;
}
.action .menu h3 {
width: 100%;
text-align: center;
font-size: 18px;
padding: 20px 0;
font-weight: 500;
color: #555;
line-height: 1.5em;
}
.action .menu h3 span {
font-size: 14px;
color: #cecece;
font-weight: 300;
}
.action .menu ul li {
list-style: none;
padding: 16px 0;
border-top: 1px solid rgba(0, 0, 0, 0.05);
display: flex;
align-items: center;
}
.action .menu ul li img {
max-width: 20px;
margin-right: 10px;
opacity: 0.5;
transition: 0.5s;
}
.action .menu ul li:hover img {
opacity: 1;
}
.action .menu ul li a {
display: inline-block;
text-decoration: none;
color: #555;
font-weight: 500;
transition: 0.5s;
}
.action .menu ul li:hover a {
color: #9370DB;
}
.responsive-wrapper {
width: 90%;
max-width: 1280px;
margin-left: auto;
margin-right: auto;
}
.button {
font: inherit;
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 1em;
height: 40px;
border-radius: 8px;
line-height: 1;
border: 2px solid var(--c-border-primary);
color: var(--c-text-action);
font-size: 0.875rem;
transition: 0.15s ease;
background-color: var(--c-background-primary);
}
.button i {
margin-right: 0.5rem;
font-size: 1.25em;
}
.button span {
font-weight: 500;
}
.button:hover, .button:focus {
border-color: var(--c-accent-primary);
color: var(--c-accent-primary);
}
.main {
padding-top: 3rem;
}
.main-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.main-header h1 {
font-size: 1.75rem;
font-weight: 600;
line-height: 1.25;
}
#media (max-width: 550px) {
.main-header h1 {
margin-bottom: 1rem;
}
}
.search {
position: relative;
display: flex;
align-items: center;
width: 100%;
max-width: 340px;
}
.search input {
font: inherit;
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 1em 0 36px;
height: 40px;
border-radius: 8px;
border: 2px solid var(--c-border-primary);
color: var(--c-text-action);
font-size: 0.875rem;
transition: 0.15s ease;
width: 100%;
line-height: 1;
}
.search input::-moz-placeholder {
color: var(--c-text-action);
}
.search input:-ms-input-placeholder {
color: var(--c-text-action);
}
.search input::placeholder {
color: var(--c-text-action);
}
.search input:focus, .search input:hover {
border-color: var(--c-accent-primary);
}
.search button {
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background-color: transparent;
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
font-size: 1.25em;
color: var(--c-text-action);
padding: 0;
height: 40px;
}
.horizontal-tabs {
margin-top: 1.5rem;
display: flex;
align-items: center;
overflow-x: auto;
}
#media (max-width: 1000px) {
.horizontal-tabs {
scrollbar-width: none;
position: relative;
}
.horizontal-tabs::-webkit-scrollbar {
display: none;
}
}
.horizontal-tabs a {
display: inline-flex;
flex-shrink: 0;
align-items: center;
height: 48px;
padding: 0 0.25rem;
font-weight: 500;
color: inherit;
border-bottom: 3px solid transparent;
text-decoration: none;
transition: 0.15s ease;
}
.horizontal-tabs a:hover, .horizontal-tabs a:focus, .horizontal-tabs a.active {
color: var(--c-accent-primary);
border-bottom-color: var(--c-accent-primary);
}
.horizontal-tabs a + * {
margin-left: 1rem;
}
.content-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
padding-top: 3rem;
margin-top: -1px;
border-top: 1px solid var(--c-border-primary);
}
.content-header-intro h2 {
font-size: 1.25rem;
font-weight: 600;
}
.content-header-intro p {
color: var(--c-text-secondary);
margin-top: 0.25rem;
font-size: 0.875rem;
margin-bottom: 1rem;
}
#media (min-width: 800px) {
.content-header-actions a:first-child {
display: none;
}
}
.content {
border-top: 1px solid var(--c-border-primary);
margin-top: 2rem;
display: flex;
align-items: flex-start;
}
.content-panel {
display: none;
max-width: 280px;
width: 25%;
padding: 2rem 1rem 2rem 0;
margin-right: 3rem;
}
#media (min-width: 800px) {
.content-panel {
display: block;
}
}
.vertical-tabs {
display: flex;
flex-direction: column;
}
.vertical-tabs a {
display: flex;
align-items: center;
padding: 0.75em 1em;
background-color: transparent;
border-radius: 8px;
text-decoration: none;
font-weight: 500;
color: var(--c-text-action);
transition: 0.15s ease;
}
.vertical-tabs a:hover, .vertical-tabs a:focus, .vertical-tabs a.active {
background-color: var(--c-background-tertiary);
color: var(--c-accent-primary);
}
.vertical-tabs a + * {
margin-top: 0.25rem;
}
.content-main {
padding-top: 2rem;
padding-bottom: 6rem;
flex-grow: 1;
}
.card-grid {
display: grid;
grid-template-columns: repeat(1, 1fr);
-moz-column-gap: 1.5rem;
column-gap: 1.5rem;
row-gap: 1.5rem;
}
#media (min-width: 600px) {
.card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
#media (min-width: 1200px) {
.card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
.card {
background-color: var(--c-background-primary);
box-shadow: 0 3px 3px 0 rgba(0, 0, 0, 0.05), 0 5px 15px 0 rgba(0, 0, 0, 0.05);
border-radius: 8px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 1.5rem 1.25rem 1rem 1.25rem;
}
.card-header div {
display: flex;
align-items: center;
}
.card-header div span {
width: 40px;
height: 40px;
border-radius: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
}
.card-header div span img {
max-height: 100%;
}
.card-header div h3 {
margin-left: 0.75rem;
font-weight: 500;
}
.toggle span {
display: block;
width: 40px;
height: 24px;
border-radius: 99em;
background-color: var(--c-background-quaternary);
box-shadow: inset 1px 1px 1px 0 rgba(0, 0, 0, 0.05);
position: relative;
transition: 0.15s ease;
}
.toggle span:before {
content: "";
display: block;
position: absolute;
left: 3px;
top: 3px;
height: 18px;
width: 18px;
background-color: var(--c-background-primary);
border-radius: 50%;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.15);
transition: 0.15s ease;
}
.toggle input {
clip: rect(0 0 0 0);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.toggle input:checked + span {
background-color: var(--c-accent-primary);
}
.toggle input:checked + span:before {
transform: translateX(calc(100% - 2px));
}
.toggle input:focus + span {
box-shadow: 0 0 0 4px var(--c-background-tertiary);
}
.card-body {
padding: 1rem 1.25rem;
font-size: 0.875rem;
}
.card-footer {
margin-top: auto;
padding: 1rem 1.25rem;
display: flex;
align-items: center;
justify-content: flex-end;
border-top: 1px solid rgba(0,0,0,.125);
}
.card-footer a {
color: var(--c-text-action);
text-decoration: none;
font-weight: 500;
font-size: 0.875rem;
}
html::-webkit-scrollbar {
width: 12px;
}
html::-webkit-scrollbar-thumb {
background-color: var(--c-text-primary);
border: 4px solid var(--c-background-primary);
border-radius: 99em;
}
You are using Bootstrap 5, yet you did not linked it in the head:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
Then change the structure of your Navbar:
<!---Navbar--->
<header>
<div class="navbar navbar-expand-md">
<div class="container">
Logo Here
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainmenu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainmenu">
<ul class="navbar-nav ms-auto">
<li class="nav-item">Home</li>
<li class="nav-item">Page</li>
<li class="nav-item dropdown">
Dropdown
<ul class="dropdown-menu">
<li>Dropdown 01</li>
<li>Dropdown 02</li>
</ul>
</li>
<li class="nav-item">Contact</li>
</ul>
</div>
</div>
</div>
</header>
<!---Navbar--->
And finally, remove the custom CSS you made in your CSS file. Eventually, in the css file, search for Nav and delete everything related to the navbar
This question already has answers here:
How to remove/disable styling on some bootstrap elements
(5 answers)
Removing bootstrap styling from certain elements
(1 answer)
How do you completely remove a style from bootstrap by overriding it
(2 answers)
How can I remove a Bootstrap CSS styling for a specific element?
(1 answer)
How can I override Bootstrap CSS styles?
(14 answers)
Closed 5 months ago.
I added the Bootstrap styling link in my page head, but it adds some extra styling to my cards that I don't want. How can I remove it without deleting the Bootstrap CSS link?
I have provided a screenshot and my code below.
How I want to keep it
How it looks when BS CSS link gets added
function switchTabs() {
document.querySelectorAll(".tab-button").forEach(link => {
link.addEventListener("click", () => {
const menuBar = link.parentElement;
const tabsContainer = menuBar.parentElement;
const tabNumber = link.dataset.forTab;
const tabToActivate = tabsContainer.querySelector(`[data-tab="${tabNumber}"]`)
menuBar.querySelectorAll(".tab-button").forEach(link => {
link.classList.remove("tab-button-active");
})
tabsContainer.querySelectorAll(".content").forEach(tab => {
tab.classList.remove("content-active");
})
link.classList.add("tab-button-active");
tabToActivate.classList.add("content-active");
});
});
}
document.addEventListener("DOMContentLoaded", () => {
switchTabs();
document.querySelectorAll(".content").forEach(tabsContainer => {
document.querySelector(".horizontal-tabs .tab-button").click()
})
});
function menuToggle() {
const toggleMenu = document.querySelector(".menu");
toggleMenu.classList.toggle("active");
}
#import url("https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
:root {
--c-text-primary: #282a32;
--c-text-secondary: #686b87;
--c-text-action: #404089;
--c-accent-primary: #434ce8;
--c-border-primary: #eff1f6;
--c-background-primary: #ffffff;
--c-background-secondary: #fdfcff;
--c-background-tertiary: #ecf3fe;
--c-background-quaternary: #e9ecf4;
}
body {
line-height: 1.5;
min-height: 100vh;
font-family: "Be Vietnam Pro", sans-serif;
background-color: #E5E5E5 !important;
color: var(--c-text-primary);
}
:focus {
outline: 0;
}
.navbar-light {
background-color: #ffffff;
}
.navbar-nav {
justify-content: space-between;
}
.navbar-brand {
font-size: 45px;
color: #A388E7 !important;
font-weight: bolder;
padding-top: 0.3125rem;
padding-bottom: 0.3125rem;
margin-right: 1rem;
text-decoration: none;
white-space: nowrap;
}
.nav-item {
color: #686868 !important;
font-size: 20px;
position: relative;
right: -1675px !important;
}
.nav-item a {
display: block;
padding: 0.5rem 1rem;
color: #000000;
text-decoration: none;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out;
}
#alert {
position: relative;
right: -3px !important;
}
.action {
position: fixed;
top: 20px;
right: 30px;
}
.action .profile {
position: relative;
width: 60px;
height: 60px;
border-radius: 50%;
overflow: hidden;
cursor: pointer;
}
.action .profile img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.action .menu {
position: absolute;
top: 120px;
right: -10px;
padding: 10px 20px;
background: #fff;
width: 200px;
box-sizing: 0 5px 25px rgba(0, 0, 0, 0.1);
border-radius: 15px;
transition: 0.5s;
visibility: hidden;
opacity: 0;
}
.action .menu.active {
top: 80px;
visibility: visible;
opacity: 1;
}
.action .menu::before {
content: "";
position: absolute;
top: -5px;
right: 28px;
width: 20px;
height: 20px;
background: #fff;
transform: rotate(45deg);
}
*,
::after,
::before {
box-sizing: border-box;
}
.action .menu h3 {
width: 100%;
text-align: center;
font-size: 18px;
padding: 20px 0;
font-weight: 500;
color: #555;
line-height: 1.5em;
}
.action .menu h3 span {
font-size: 14px;
color: #cecece;
font-weight: 300;
}
.action .menu ul li {
list-style: none;
padding: 16px 0;
border-top: 1px solid rgba(0, 0, 0, 0.05);
display: flex;
align-items: center;
}
.action .menu ul li img {
max-width: 20px;
margin-right: 10px;
opacity: 0.5;
transition: 0.5s;
}
.action .menu ul li:hover img {
opacity: 1;
}
.action .menu ul li a {
display: inline-block;
text-decoration: none;
color: #555;
font-weight: 500;
transition: 0.5s;
}
.action .menu ul li:hover a {
color: #9370DB;
}
.responsive-wrapper {
width: 90%;
max-width: 1280px;
margin-left: auto;
margin-right: auto;
}
.button {
font: inherit;
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 1em;
height: 40px;
border-radius: 8px;
line-height: 1;
border: 2px solid var(--c-border-primary);
color: var(--c-text-action);
font-size: 0.875rem;
transition: 0.15s ease;
background-color: var(--c-background-primary);
}
.button i {
margin-right: 0.5rem;
font-size: 1.25em;
}
.button span {
font-weight: 500;
}
.button:hover,
.button:focus {
border-color: var(--c-accent-primary);
color: var(--c-accent-primary);
}
.main {
padding-top: 3rem;
}
.main-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.main-header h1 {
font-size: 1.75rem;
font-weight: 600;
line-height: 1.25;
}
#media (max-width: 550px) {
.main-header h1 {
margin-bottom: 1rem;
}
}
.search {
position: relative;
display: flex;
align-items: center;
width: 100%;
max-width: 340px;
}
.search input {
font: inherit;
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 1em 0 36px;
height: 40px;
border-radius: 8px;
border: 2px solid var(--c-border-primary);
color: var(--c-text-action);
font-size: 0.875rem;
transition: 0.15s ease;
width: 100%;
line-height: 1;
}
.search input::-moz-placeholder {
color: var(--c-text-action);
}
.search input:-ms-input-placeholder {
color: var(--c-text-action);
}
.search input::placeholder {
color: var(--c-text-action);
}
.search input:focus,
.search input:hover {
border-color: var(--c-accent-primary);
}
.search button {
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background-color: transparent;
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
font-size: 1.25em;
color: var(--c-text-action);
padding: 0;
height: 40px;
}
.horizontal-tabs {
margin-top: 1.5rem;
display: flex;
align-items: center;
overflow-x: auto;
}
#media (max-width: 1000px) {
.horizontal-tabs {
scrollbar-width: none;
position: relative;
}
.horizontal-tabs::-webkit-scrollbar {
display: none;
}
}
.horizontal-tabs a {
display: inline-flex;
flex-shrink: 0;
align-items: center;
height: 48px;
padding: 0 0.25rem;
font-weight: 500;
color: inherit;
border-bottom: 3px solid transparent;
text-decoration: none;
transition: 0.15s ease;
}
.horizontal-tabs a:hover,
.horizontal-tabs a:focus,
.horizontal-tabs a.active {
color: var(--c-accent-primary);
border-bottom-color: var(--c-accent-primary);
}
.horizontal-tabs a+* {
margin-left: 1rem;
}
.content-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
padding-top: 3rem;
margin-top: -1px;
border-top: 1px solid var(--c-border-primary);
width: 100%;
}
.content-header-intro h2 {
font-size: 1.25rem;
font-weight: 600;
}
.content-header-intro p {
color: var(--c-text-secondary);
margin-top: 0.25rem;
font-size: 0.875rem;
margin-bottom: 1rem;
}
#media (min-width: 800px) {
.content-header-actions a:first-child {
display: none;
}
}
.content {
border-top: 1px solid var(--c-border-primary);
margin-top: 2rem;
display: none;
flex-direction: column;
}
.content-active {
display: flex !important;
}
.content-panel {
display: none;
max-width: 280px;
width: 25%;
padding: 2rem 1rem 2rem 0;
margin-right: 3rem;
}
.content-main-wrapper {
width: 100%;
display: flex;
flex-direction: row;
}
#media (min-width: 800px) {
.content-panel {
display: block;
}
}
.vertical-tabs {
display: flex;
flex-direction: column;
}
.vertical-tabs a {
display: flex;
align-items: center;
padding: 0.75em 1em;
background-color: transparent;
border-radius: 8px;
text-decoration: none;
font-weight: 500;
color: var(--c-text-action);
transition: 0.15s ease;
}
.vertical-tabs a:hover,
.vertical-tabs a:focus,
.vertical-tabs a.active {
background-color: var(--c-background-tertiary);
color: var(--c-accent-primary);
}
.vertical-tabs a+* {
margin-top: 0.25rem;
}
.content-main {
padding-top: 2rem;
padding-bottom: 6rem;
flex-grow: 1;
}
.card-grid {
display: grid;
grid-template-columns: repeat(1, 1fr);
-moz-column-gap: 1.5rem;
column-gap: 1.5rem;
row-gap: 1.5rem;
}
#media (min-width: 600px) {
.card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
#media (min-width: 1200px) {
.card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
.card {
background-color: var(--c-background-primary);
box-shadow: 0 3px 3px 0 rgba(0, 0, 0, 0.05), 0 5px 15px 0 rgba(0, 0, 0, 0.05);
border-radius: 8px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 1.5rem 1.25rem 1rem 1.25rem;
}
.card-header div {
display: flex;
align-items: center;
}
.card-header div span {
width: 40px;
height: 40px;
border-radius: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
}
.card-header div span img {
max-height: 100%;
}
.card-header div h3 {
margin-left: 0.75rem;
font-weight: 500;
}
/*---Profile---*/
/*---Profile---*/
.toggle span {
display: block;
width: 40px;
height: 24px;
border-radius: 99em;
background-color: var(--c-background-quaternary);
box-shadow: inset 1px 1px 1px 0 rgba(0, 0, 0, 0.05);
position: relative;
transition: 0.15s ease;
}
.toggle span:before {
content: "";
display: block;
position: absolute;
left: 3px;
top: 3px;
height: 18px;
width: 18px;
background-color: var(--c-background-primary);
border-radius: 50%;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.15);
transition: 0.15s ease;
}
.toggle input {
clip: rect(0 0 0 0);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.toggle input:checked+span {
background-color: var(--c-accent-primary);
}
.toggle input:checked+span:before {
transform: translateX(calc(100% - 2px));
}
.toggle input:focus+span {
box-shadow: 0 0 0 4px var(--c-background-tertiary);
}
.card-body {
padding: 1rem 1.25rem;
font-size: 0.875rem;
}
.card-footer {
margin-top: auto;
padding: 1rem 1.25rem;
display: flex;
align-items: center;
justify-content: flex-end;
border-top: 1px solid rgba(0, 0, 0, .125);
}
.card-footer a {
color: var(--c-text-action);
text-decoration: none;
font-weight: 500;
font-size: 0.875rem;
}
.tab-button-active {
color: var(--c-accent-primary) !important;
border-bottom: 3px solid var(--c-accent-primary) !important;
}
html::-webkit-scrollbar {
width: 12px;
}
html::-webkit-scrollbar-thumb {
background-color: var(--c-text-primary);
border: 4px solid var(--c-background-primary);
border-radius: 99em;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>StudioPick</title>
<!---Bootstrap CSS--->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel="stylesheet" href="CSS/settings.css">
</head>
<body>
<!---Navbar--->
<header>
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container-fluid">
<a style="font-size: 45px; color: #A388E7;" class="navbar-brand" href="#"><strong>StudioPick</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-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 ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-curresnt="page" href="index.html">Home</a>
</li>
<li class="nav-item2">
<div class="action">
<div class="profile" onclick="menuToggle();">
<img src="./assets/avatar.jpg" />
</div>
<div class="menu">
<h3 id="profile-name"><strong>User Name</strong></h3>
<p class="text-muted" id="userType"
style="position: relative; top: -20px; right: -60px; font-size: 12px !important">
Studio</p>
<ul>
<li>
<img src="./assets/icons/user.png" />Dashboard
</li>
<li>
<img src="./assets/icons/edit.png" /><a href="editprofile.html">Edit
profile</a>
</li>
<li>
<img src="./assets/icons/envelope.png" />Inbox
</li>
<li>
<img src="./assets/icons/settings.png" />Setting
</li>
<li><img src="./assets/icons/question.png" />Help</li>
<li>
<img src="./assets/icons/log-out.png" /><a href="#"
onclick="signOut();">Logout</a>
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!---Navbar--->
<main class="main">
<div class="responsive-wrapper">
<div class="main-header">
<h1>Settings</h1>
<div class="search">
<input type="text" placeholder="Search" />
<button type="submit">
<i class="ph-magnifying-glass-bold"></i>
</button>
</div>
</div>
<div class="horizontal-tabs">
<a class="tab-button" href="#" data-for-tab="1">Profile</a>
<a class="tab-button" href="#" data-for-tab="2">My Rooms</a>
<a class="tab-button" href="#" data-for-tab="3">Session Management</a>
<a class="tab-button" href="#" data-for-tab="4">Payment History</a>
<a class="tab-button" href="#" data-for-tab="5">Edit Payment</a>
</div>
<!---Tab 1--->
<div class="content" data-tab="1">
<div class="content-header">
<div class="content-header-intro">
<h2>Manage your profile</h2>
<p>Edit your profile information such email, username, password, etc.</p>
</div>
</div>
<div class="content-main-wrapper">
<div class="content-main">
<h3>Legal Name</h3>
<p class="legalName text-muted">User's Legal Name</p>
</div>
</div>
</div>
<!---Tab 1--->
<!---Tab 2--->
<div class="content" data-tab="2">
<div class="content-header">
<div class="content-header-intro">
<h2>Manage your studio rooms</h2>
<p>Add, delete, and edit the room images for your studio profile.</p>
</div>
<div class="content-header-actions">
<a href="#" class="button">
<i class="ph-faders-bold"></i>
<span>Filters</span>
</a>
<a href="#" class="button">
<i class="ph-plus-bold"></i>
<span>Add a room</span>
</a>
</div>
</div>
<div class="content-main-wrapper">
<div class="content-panel">
<div class="vertical-tabs">
View Rooms
Manage Services
</div>
</div>
<div class="content-main">
<div class="card-grid">
<article class="card">
<div class="card-header">
<div>
<span><img src="https://assets.codepen.io/285131/zeplin.svg" /></span>
<h3>Room A</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Add room's content</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
<article class="card">
<div class="card-header">
<div>
<span><img src="https://assets.codepen.io/285131/github.svg" /></span>
<h3>Room B</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Add room's content</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
<article class="card">
<div class="card-header">
<div>
<span><img src="https://assets.codepen.io/285131/figma.svg" /></span>
<h3>Room C</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Add room's content</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
</div>
</div>
</div>
</div>
<!---Tab 2--->
<!---Tab 3--->
<div class="content" data-tab="3">
<div class="content-panel">
<div class="vertical-tabs">
</div>
</div>
<div class="content-main-wrapper">
<div class="content-main">
<div class="card-grid">
</div>
</div>
</div>
</div>
<!---Tab 3--->
</div>
</main>
<!-- partial -->
<script src='https://unpkg.com/phosphor-icons'></script>
<script src="Javascript/settings.js"></script>
<!----More Bootstrap--->
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.10.2/dist/umd/popper.min.js"
integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js"
integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13"
crossorigin="anonymous"></script>
<!----More Bootstrap--->
</body>
</html>
You can add other Bootstrap classes to .card-header which is where the background and border come from.
You can use bg-white for the white background and border-0 for no border.
function switchTabs() {
document.querySelectorAll(".tab-button").forEach(link => {
link.addEventListener("click", () => {
const menuBar = link.parentElement;
const tabsContainer = menuBar.parentElement;
const tabNumber = link.dataset.forTab;
const tabToActivate = tabsContainer.querySelector(`[data-tab="${tabNumber}"]`)
menuBar.querySelectorAll(".tab-button").forEach(link => {
link.classList.remove("tab-button-active");
})
tabsContainer.querySelectorAll(".content").forEach(tab => {
tab.classList.remove("content-active");
})
link.classList.add("tab-button-active");
tabToActivate.classList.add("content-active");
});
});
}
document.addEventListener("DOMContentLoaded", () => {
switchTabs();
document.querySelectorAll(".content").forEach(tabsContainer => {
document.querySelector(".horizontal-tabs .tab-button").click()
})
});
function menuToggle() {
const toggleMenu = document.querySelector(".menu");
toggleMenu.classList.toggle("active");
}
#import url("https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
:root {
--c-text-primary: #282a32;
--c-text-secondary: #686b87;
--c-text-action: #404089;
--c-accent-primary: #434ce8;
--c-border-primary: #eff1f6;
--c-background-primary: #ffffff;
--c-background-secondary: #fdfcff;
--c-background-tertiary: #ecf3fe;
--c-background-quaternary: #e9ecf4;
}
body {
line-height: 1.5;
min-height: 100vh;
font-family: "Be Vietnam Pro", sans-serif;
background-color: #E5E5E5 !important;
color: var(--c-text-primary);
}
:focus {
outline: 0;
}
.navbar-light {
background-color: #ffffff;
}
.navbar-nav {
justify-content: space-between;
}
.navbar-brand {
font-size: 45px;
color: #A388E7 !important;
font-weight: bolder;
padding-top: 0.3125rem;
padding-bottom: 0.3125rem;
margin-right: 1rem;
text-decoration: none;
white-space: nowrap;
}
.nav-item {
color: #686868 !important;
font-size: 20px;
position: relative;
right: -1675px !important;
}
.nav-item a {
display: block;
padding: 0.5rem 1rem;
color: #000000;
text-decoration: none;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out;
}
#alert {
position: relative;
right: -3px !important;
}
.action {
position: fixed;
top: 20px;
right: 30px;
}
.action .profile {
position: relative;
width: 60px;
height: 60px;
border-radius: 50%;
overflow: hidden;
cursor: pointer;
}
.action .profile img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.action .menu {
position: absolute;
top: 120px;
right: -10px;
padding: 10px 20px;
background: #fff;
width: 200px;
box-sizing: 0 5px 25px rgba(0, 0, 0, 0.1);
border-radius: 15px;
transition: 0.5s;
visibility: hidden;
opacity: 0;
}
.action .menu.active {
top: 80px;
visibility: visible;
opacity: 1;
}
.action .menu::before {
content: "";
position: absolute;
top: -5px;
right: 28px;
width: 20px;
height: 20px;
background: #fff;
transform: rotate(45deg);
}
*,
::after,
::before {
box-sizing: border-box;
}
.action .menu h3 {
width: 100%;
text-align: center;
font-size: 18px;
padding: 20px 0;
font-weight: 500;
color: #555;
line-height: 1.5em;
}
.action .menu h3 span {
font-size: 14px;
color: #cecece;
font-weight: 300;
}
.action .menu ul li {
list-style: none;
padding: 16px 0;
border-top: 1px solid rgba(0, 0, 0, 0.05);
display: flex;
align-items: center;
}
.action .menu ul li img {
max-width: 20px;
margin-right: 10px;
opacity: 0.5;
transition: 0.5s;
}
.action .menu ul li:hover img {
opacity: 1;
}
.action .menu ul li a {
display: inline-block;
text-decoration: none;
color: #555;
font-weight: 500;
transition: 0.5s;
}
.action .menu ul li:hover a {
color: #9370DB;
}
.responsive-wrapper {
width: 90%;
max-width: 1280px;
margin-left: auto;
margin-right: auto;
}
.button {
font: inherit;
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 1em;
height: 40px;
border-radius: 8px;
line-height: 1;
border: 2px solid var(--c-border-primary);
color: var(--c-text-action);
font-size: 0.875rem;
transition: 0.15s ease;
background-color: var(--c-background-primary);
}
.button i {
margin-right: 0.5rem;
font-size: 1.25em;
}
.button span {
font-weight: 500;
}
.button:hover,
.button:focus {
border-color: var(--c-accent-primary);
color: var(--c-accent-primary);
}
.main {
padding-top: 3rem;
}
.main-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.main-header h1 {
font-size: 1.75rem;
font-weight: 600;
line-height: 1.25;
}
#media (max-width: 550px) {
.main-header h1 {
margin-bottom: 1rem;
}
}
.search {
position: relative;
display: flex;
align-items: center;
width: 100%;
max-width: 340px;
}
.search input {
font: inherit;
color: inherit;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 1em 0 36px;
height: 40px;
border-radius: 8px;
border: 2px solid var(--c-border-primary);
color: var(--c-text-action);
font-size: 0.875rem;
transition: 0.15s ease;
width: 100%;
line-height: 1;
}
.search input::-moz-placeholder {
color: var(--c-text-action);
}
.search input:-ms-input-placeholder {
color: var(--c-text-action);
}
.search input::placeholder {
color: var(--c-text-action);
}
.search input:focus,
.search input:hover {
border-color: var(--c-accent-primary);
}
.search button {
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background-color: transparent;
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
font-size: 1.25em;
color: var(--c-text-action);
padding: 0;
height: 40px;
}
.horizontal-tabs {
margin-top: 1.5rem;
display: flex;
align-items: center;
overflow-x: auto;
}
#media (max-width: 1000px) {
.horizontal-tabs {
scrollbar-width: none;
position: relative;
}
.horizontal-tabs::-webkit-scrollbar {
display: none;
}
}
.horizontal-tabs a {
display: inline-flex;
flex-shrink: 0;
align-items: center;
height: 48px;
padding: 0 0.25rem;
font-weight: 500;
color: inherit;
border-bottom: 3px solid transparent;
text-decoration: none;
transition: 0.15s ease;
}
.horizontal-tabs a:hover,
.horizontal-tabs a:focus,
.horizontal-tabs a.active {
color: var(--c-accent-primary);
border-bottom-color: var(--c-accent-primary);
}
.horizontal-tabs a+* {
margin-left: 1rem;
}
.content-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
padding-top: 3rem;
margin-top: -1px;
border-top: 1px solid var(--c-border-primary);
width: 100%;
}
.content-header-intro h2 {
font-size: 1.25rem;
font-weight: 600;
}
.content-header-intro p {
color: var(--c-text-secondary);
margin-top: 0.25rem;
font-size: 0.875rem;
margin-bottom: 1rem;
}
#media (min-width: 800px) {
.content-header-actions a:first-child {
display: none;
}
}
.content {
border-top: 1px solid var(--c-border-primary);
margin-top: 2rem;
display: none;
flex-direction: column;
}
.content-active {
display: flex !important;
}
.content-panel {
display: none;
max-width: 280px;
width: 25%;
padding: 2rem 1rem 2rem 0;
margin-right: 3rem;
}
.content-main-wrapper {
width: 100%;
display: flex;
flex-direction: row;
}
#media (min-width: 800px) {
.content-panel {
display: block;
}
}
.vertical-tabs {
display: flex;
flex-direction: column;
}
.vertical-tabs a {
display: flex;
align-items: center;
padding: 0.75em 1em;
background-color: transparent;
border-radius: 8px;
text-decoration: none;
font-weight: 500;
color: var(--c-text-action);
transition: 0.15s ease;
}
.vertical-tabs a:hover,
.vertical-tabs a:focus,
.vertical-tabs a.active {
background-color: var(--c-background-tertiary);
color: var(--c-accent-primary);
}
.vertical-tabs a+* {
margin-top: 0.25rem;
}
.content-main {
padding-top: 2rem;
padding-bottom: 6rem;
flex-grow: 1;
}
.card-grid {
display: grid;
grid-template-columns: repeat(1, 1fr);
-moz-column-gap: 1.5rem;
column-gap: 1.5rem;
row-gap: 1.5rem;
}
#media (min-width: 600px) {
.card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
#media (min-width: 1200px) {
.card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
.card {
background-color: var(--c-background-primary);
box-shadow: 0 3px 3px 0 rgba(0, 0, 0, 0.05), 0 5px 15px 0 rgba(0, 0, 0, 0.05);
border-radius: 8px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 1.5rem 1.25rem 1rem 1.25rem;
}
.card-header div {
display: flex;
align-items: center;
}
.card-header div span {
width: 40px;
height: 40px;
border-radius: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
}
.card-header div span img {
max-height: 100%;
}
.card-header div h3 {
margin-left: 0.75rem;
font-weight: 500;
}
/*---Profile---*/
/*---Profile---*/
.toggle span {
display: block;
width: 40px;
height: 24px;
border-radius: 99em;
background-color: var(--c-background-quaternary);
box-shadow: inset 1px 1px 1px 0 rgba(0, 0, 0, 0.05);
position: relative;
transition: 0.15s ease;
}
.toggle span:before {
content: "";
display: block;
position: absolute;
left: 3px;
top: 3px;
height: 18px;
width: 18px;
background-color: var(--c-background-primary);
border-radius: 50%;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.15);
transition: 0.15s ease;
}
.toggle input {
clip: rect(0 0 0 0);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.toggle input:checked+span {
background-color: var(--c-accent-primary);
}
.toggle input:checked+span:before {
transform: translateX(calc(100% - 2px));
}
.toggle input:focus+span {
box-shadow: 0 0 0 4px var(--c-background-tertiary);
}
.card-body {
padding: 1rem 1.25rem;
font-size: 0.875rem;
}
.card-footer {
margin-top: auto;
padding: 1rem 1.25rem;
display: flex;
align-items: center;
justify-content: flex-end;
border-top: 1px solid rgba(0, 0, 0, .125);
}
.card-footer a {
color: var(--c-text-action);
text-decoration: none;
font-weight: 500;
font-size: 0.875rem;
}
.tab-button-active {
color: var(--c-accent-primary) !important;
border-bottom: 3px solid var(--c-accent-primary) !important;
}
html::-webkit-scrollbar {
width: 12px;
}
html::-webkit-scrollbar-thumb {
background-color: var(--c-text-primary);
border: 4px solid var(--c-background-primary);
border-radius: 99em;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>StudioPick</title>
<!---Bootstrap CSS--->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel="stylesheet" href="CSS/settings.css">
</head>
<body>
<!---Navbar--->
<header>
<nav class="navbar navbar-expand-lg navbar-light">
<div class="container-fluid">
<a style="font-size: 45px; color: #A388E7;" class="navbar-brand" href="#"><strong>StudioPick</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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 ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-curresnt="page" href="index.html">Home</a>
</li>
<li class="nav-item2">
<div class="action">
<div class="profile" onclick="menuToggle();">
<img src="./assets/avatar.jpg" />
</div>
<div class="menu">
<h3 id="profile-name"><strong>User Name</strong></h3>
<p class="text-muted" id="userType" style="position: relative; top: -20px; right: -60px; font-size: 12px !important">
Studio</p>
<ul>
<li>
<img src="./assets/icons/user.png" />Dashboard
</li>
<li>
<img src="./assets/icons/edit.png" /><a href="editprofile.html">Edit
profile</a>
</li>
<li>
<img src="./assets/icons/envelope.png" />Inbox
</li>
<li>
<img src="./assets/icons/settings.png" />Setting
</li>
<li><img src="./assets/icons/question.png" />Help</li>
<li>
<img src="./assets/icons/log-out.png" />Logout
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!---Navbar--->
<main class="main">
<div class="responsive-wrapper">
<div class="main-header">
<h1>Settings</h1>
<div class="search">
<input type="text" placeholder="Search" />
<button type="submit">
<i class="ph-magnifying-glass-bold"></i>
</button>
</div>
</div>
<div class="horizontal-tabs">
<a class="tab-button" href="#" data-for-tab="1">Profile</a>
<a class="tab-button" href="#" data-for-tab="2">My Rooms</a>
<a class="tab-button" href="#" data-for-tab="3">Session Management</a>
<a class="tab-button" href="#" data-for-tab="4">Payment History</a>
<a class="tab-button" href="#" data-for-tab="5">Edit Payment</a>
</div>
<!---Tab 1--->
<div class="content" data-tab="1">
<div class="content-header">
<div class="content-header-intro">
<h2>Manage your profile</h2>
<p>Edit your profile information such email, username, password, etc.</p>
</div>
</div>
<div class="content-main-wrapper">
<div class="content-main">
<h3>Legal Name</h3>
<p class="legalName text-muted">User's Legal Name</p>
</div>
</div>
</div>
<!---Tab 1--->
<!---Tab 2--->
<div class="content" data-tab="2">
<div class="content-header">
<div class="content-header-intro">
<h2>Manage your studio rooms</h2>
<p>Add, delete, and edit the room images for your studio profile.</p>
</div>
<div class="content-header-actions">
<a href="#" class="button">
<i class="ph-faders-bold"></i>
<span>Filters</span>
</a>
<a href="#" class="button">
<i class="ph-plus-bold"></i>
<span>Add a room</span>
</a>
</div>
</div>
<div class="content-main-wrapper">
<div class="content-panel">
<div class="vertical-tabs">
View Rooms
Manage Services
</div>
</div>
<div class="content-main">
<div class="card-grid">
<article class="card">
<div class="card-header bg-white border-0">
<div>
<span><img src="https://assets.codepen.io/285131/zeplin.svg" /></span>
<h3>Room A</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Add room's content</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
<article class="card">
<div class="card-header bg-white border-0">
<div>
<span><img src="https://assets.codepen.io/285131/github.svg" /></span>
<h3>Room B</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Add room's content</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
<article class="card">
<div class="card-header bg-white border-0">
<div>
<span><img src="https://assets.codepen.io/285131/figma.svg" /></span>
<h3>Room C</h3>
</div>
<label class="toggle">
<input type="checkbox" checked>
<span></span>
</label>
</div>
<div class="card-body">
<p>Add room's content</p>
</div>
<div class="card-footer">
View integration
</div>
</article>
</div>
</div>
</div>
</div>
<!---Tab 2--->
<!---Tab 3--->
<div class="content" data-tab="3">
<div class="content-panel">
<div class="vertical-tabs">
</div>
</div>
<div class="content-main-wrapper">
<div class="content-main">
<div class="card-grid">
</div>
</div>
</div>
</div>
<!---Tab 3--->
</div>
</main>
<!-- partial -->
<script src='https://unpkg.com/phosphor-icons'></script>
<script src="Javascript/settings.js"></script>
<!----More Bootstrap--->
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<!----More Bootstrap--->
</body>
</html>
Solution 1
You can override Bootstrap's styles.
.card-header {
background: white;
border: none;
}
in case this doesn't work, consider using !important
Solution 2
If you want to keep .card-header's styles for your application but just want to change it in one place then add a custom class to your .card-header div and style it accordingly.
PS: CSS libraries do not always provide the desired styling or classes you want. So it's best to learn what to do in such cases.
I was trying my best to do a down menu for my project and I was searching on youtube for about a week and it was useless.
The code hints:
The commented code are unfinished code that still I have to edit
Most of code are not styled yet because I am still testing the code of the development menu
HTML:
<!DOCTYPE html>
<html lang="en">
<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>ABF</title>
<link rel="stylesheet" href="style.css" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
/>
</head>
<body>
<header>
<ul class="right-side">
<li>
<a class="header-title">abf</a>
</li>
<li class="menu">
<a class="header-courses">courses<i class="fas fa-caret-down"></i></a>
<div class="sub-menu-div">
<ul class="sub-menu">
<li class="development-menu">
Development
<i class="fa-solid fa-caret-right development-right-arrow"></i>
<div class="development-down-menu">
<ul>
<li>Front end</li>
<li>Back end</li>
</ul>
</div>
</li>
<li class="business-menu">
Business
<i class="fa-solid fa-caret-right business-right-arrow"></i>
<!-- <div class="business-down-menu">
<ul>
<li>Management </li>
<li>Sales</li>
</ul>
</div> -->
</li>
<li class="IT--Software-menu">
IT & Software
<i class="fa-solid fa-caret-right IT--Software-right-arrow"></i>
<!-- <div class="IT--Software-down-menu">
<ul>
<li>Hardware </li>
<li>Network & Security</li>
</ul>
</div> -->
</li>
<li class="Finance--Accounting-menu">
Finance & Accounting
<i class="fa-solid fa-caret-right Finance--Accounting-right-arrow"></i>
<!-- <div class="Finance--Accounting-down-menu">
<ul>
<li>Finance </li>
<li>Economics</li>
</ul>
</div> -->
</li>
<li class="Design-menu">
Design
<i class="fa-solid fa-caret-right Design-right-arrow"></i>
<!-- <div class="Design-down-menu">
<ul>
<li>Web Design </li>
<li>Game Design</li>
</ul>
</div> -->
</li>
<li class="markting-menu">
markting
<i class="fa-solid fa-caret-right markting-right-arrow"></i>
<!-- <div class="marketing-down-menu">
<ul>
<li>Digital Marketing </li>
<li>Branding</li>
</ul>
</div> -->
</li>
<li class="Music-menu">
Music
<i class="fa-solid fa-caret-right Music-right-arrow"></i>
<!-- <div class="Music-down-menu">
<ul>
<li>Instruments</li>
<li>Music Production</li>
</ul>
</div> -->
</li>
</ul>
</div>
</li>
</ul>
<form class="search-bar">
<input class="search-input" type="text" placeholder="search" />
<i class="fa-solid fa-magnifying-glass"></i>
</form>
<nav>
Login
Sign up
</nav>
</header>
<section class="main-section">
<div class="main-wisdom">
<p class="wisdom">
Unlimited Content <br />
of online courses
</p>
</div>
<div class="main-shape">
<div class="main-shape1"></div>
<div class="main-shape2"></div>
<img class="man" src="images/man.png" alt="" />
</div>
</section>
<!-- <section class="some-courses">
<h2>Some Courses</h2>
<div class="courses">
<div class="Some-Courses-course">
</div>
</div>
</section> -->
</body>
</html>
CSS:
#import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght#0,400;0,500;0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&family=Poppins:ital,wght#0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
*{
padding: 0px;
margin: 0px;
box-sizing: border-box;
scroll-behavior: smooth;
}
header{
width: 100%;
background-color: white;
display: flex;
z-index: 999;
position: fixed;
align-items: center;
padding: 10px ;
box-shadow: 0px 3px 3px rgba(1, 1, 1, 15%);
position: absolute;
}
.right-side{
height: 100%;
}
.header-title{
text-decoration: none;
font-size: 2em;
font-weight: 800;
text-transform: uppercase;
padding-left: 30px;
}
.header-courses{
font-size: 1.5em;
padding-left: 30px;
padding-right: 30px;
position: relative;
top: 6px;
}
.header-courses:hover{
color: #5b0fb3;
}
.fa-caret-down{
font-size: 16px;
margin-left: 5px;
}
.courses-down-menu{
display: none;
}
.right-side{
position: relative;
display: block;
float: left;
}
.right-side > li{
float: left;
}
.sub-menu {
list-style-type: none;
display: none;
position: absolute;
padding: 20px;
width: 200px;
height: 310px;
top: 30px;
background-color: white;
box-shadow: 0px 3px 3px rgba(1, 1, 1, 15%);
}
.sub-menu li{
padding-bottom: 15px;
}
.sub-menu li a{
cursor: pointer;
text-decoration: none;
color: black;
}
.sub-menu li a:hover{
color: #5b0fb3;
}
.right-side .menu:hover .sub-menu{
display: block;
}
/* Development */
.development-menu a{
font-size: 1.2em;
list-style-type: none;
}
.development-right-arrow{
position: relative;
left: 45px;
}
.development-down-menu{
display: none;
position: absolute;
padding: 20px;
width: 150px;
height: 310px;
top: 0px;
left: 200px;
background-color: white;
box-shadow: 0px 3px 3px rgba(1, 1, 1, 15%);
}
.courses-down-menu ul {
list-style-type: none;
position: relative;
left: 20px;
padding-bottom: 15px;
}
.sub-menu-div ul li:hover .development-down-menu{
display: block;
}
/* Business */
.business-menu a{
font-size: 1.2em;
list-style-type: none;
}
.business-right-arrow{
position: relative;
left: 78px;
}
/* IT&Software */
.IT--Software-menu a{
font-size: 1.2em;
list-style-type: none;
}
.IT--Software-right-arrow{
position: relative;
left: 35px;
}
/* Finnace&Accounting */
.Finance--Accounting-menu a{
font-size: 1.2em;
list-style-type: none;
}
.Finance--Accounting-right-arrow{
position: relative;
left: 55px;
}
/* Design */
.Design-menu a{
font-size: 1.2em;
list-style-type: none;
}
.Design-right-arrow{
position: relative;
left: 88px;
}
/* marketing */
.markting-menu a{
font-size: 1.2em;
list-style-type: none;
}
.markting-right-arrow{
position: relative;
left: 73px;
}
/* Music */
.Music-menu a{
font-size: 1.2em;
list-style-type: none;
}
.Music-right-arrow{
position: relative;
left: 93px;
}
.search-bar{
background-color: #F2F0F0;
width: 800px;
height: 35px;
margin-right: 30px;
border-radius: 20px;
}
.search-input{
width: 770px;
height: 35px;
outline: none;
border: none;
background-color: #F2F0F0;
border-radius: 20px;
text-align: left;
padding-left: 20px;
}
nav{
display: block;
height: 100%;
margin-left: 30px;
}
.login{
display: inline-block;
text-decoration: none;
border: 2px solid black;
width: 100px;
height: 35px;
color: black;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
float: left;
margin-right: 10px;
}
.sign-up{
display: inline-block;
text-decoration: none;
background-color: black;
width: 100px;
height: 35px;
color: white;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
float: right;
}
.main-section{
background-color: #F4F4F4;
width: 100%;
height: 600px;
position: absolute;
}
.main-wisdom{
width: 500px;
height: 200px;
position: relative;
left: 100px;
top: 180px;
display: flex;
align-items: center;
justify-content: center;
background-color: white;
box-shadow: 0px 3px 3px rgba(1, 1, 1, 15%);
}
.wisdom{
font-family: 'Playfair Display', serif;
font-size: 3em;
}
.main-shape1{
width: 400px;
height: 250px;
position: relative;
left: 700px;
top: 150px;
background-color: #6607D6;
}
.main-shape2{
width: 340px;
height: 350px;
position: relative;
left: 950px;
bottom: 200px;
background-color: #6607D6;
}
.man{
position: relative;
bottom: 598px;
left: 805px;
size: 10px;
}
I have tried literally everything to try and make the exit icon show up on the menu by giving it an index of 999 but still no luck in making it show, any idea why it is not working?
I have added the JavaScript as well.
menuBtn.addEventListener('click' , () => {
const menu = document.querySelectorAll('.menu');
for(let el of menu){
el.style.display = 'block'
}
})
/*Navbar*/
.navbar {
width: 100%;
position: fixed;
font-family: "Ubuntu", sans-serif;
padding: 30px 0;
}
.navbar .logo a {
font-size: 2rem;
font-weight: 600;
color: white;
}
.navbar .logo a span {
color: crimson;
transition: all 0.3s ease;
}
.sticky {
padding: 30px 0;
background-color: crimson;
}
.sticky .logo a span {
color: #fff;
}
.menu li {
display: inline-block;
list-style: none;
}
.menu li a {
color: #fff;
font-size: 1.1rem;
font-weight: 500;
margin-left: 35px;
padding-left: 5px;
transition: color 0.3s ease;
}
.menu li a:hover {
border-left: 3px solid white;
color: crimson;
}
.sticky .menu li a:hover {
color: white;
}
.navbar .max-width {
display: flex;
align-items: center;
justify-content: space-between;
}
.max-width {
max-width: 1300px;
padding: 0 80px;
margin: auto;
}
/*Menu Button*/
.fa.fa-bars.menuBtn {
color: #fff;
font-size: 35px;
cursor: pointer;
display: none;
}
.fa.fa-times-circle.exit {
color: white;
font-size: 35px;
cursor: pointer;
display: none;
}
#media (max-width: 934px) {
.max-width {
padding: 0 50px;
}
.fa.fa-bars.menuBtn {
display: block;
padding-left: 10em;
}
.menu {
position: fixed;
height: 100vh;
width: 100%;
left: 0;
top: 0;
background-color: #111;
text-align: center;
padding-top: 110px;
display: none;
}
.fa.fa-times-circle.exit {
z-index: 999;
display: none;
margin: 1.8rem;
}
.menu ul li {
display: block;
}
.menu ul li a {
display: inline-block;
margin: 20px 0;
font-size: 35px;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#fortawesome/fontawesome-free#5.15.3/css/fontawesome.min.css" integrity="sha384-wESLQ85D6gbsF459vf1CiZ2+rr+CsxRY0RpiF1tLlQpDnAgg6rwdsUF1+Ics2bni" crossorigin="anonymous">
<header>
<nav class="navbar" id="nav">
<div class="max-width">
<div class="logo"><a id="headSpan" href="index.html">Port<span>folio.</span></a></div>
<div class="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Skills</li>
<li>Projects</li>
<li>CV</li>
<li>Contact</li>
</ul>
</div>
<div>
<i class="fa fa-bars menuBtn" id="menuBtn" aria-hidden="true"></i>
<i class="fa fa-times-circle exit" id="exitBtn" aria-hidden="true"></i>
</div>
</div>
</nav>
<!--Head Banner-->
<section class="home" id="home">
<div class="max-width">
<div class="home-content">
<div class="text-1">Hello, my name is</div>
<div class="text-2">Hadi Zouhbi</div>
<div class="text-3">And I'm a <span id="headSpan"><Developer></Developer></span></div>
</div>
</div>
</section>
</header>
Because it never made display:block when enter in small screen like you did for menubtn.
.fa.fa-bars.menuBtn {
display: block;
padding-left: 10em;
}
Do the same for exit icon under #media (max-width: 934px) also
.fa.fa-times-circle.exit {
display: inline-block;
}
And remove this code
.fa.fa-times-circle.exit {
z-index: 999;
display: none;
margin: 1.8rem;
}
Working example:
/*Navbar*/
body {
background-color: #ccc;
}
.navbar {
width: 100%;
position: fixed;
font-family: "Ubuntu", sans-serif;
padding: 30px 0;
}
.navbar .logo a {
font-size: 2rem;
font-weight: 600;
color: white;
}
.navbar .logo a span {
color: crimson;
transition: all 0.3s ease;
}
.sticky {
padding: 30px 0;
background-color: crimson;
}
.sticky .logo a span {
color: #fff;
}
.menu li {
display: inline-block;
list-style: none;
}
.menu li a {
color: #fff;
font-size: 1.1rem;
font-weight: 500;
margin-left: 35px;
padding-left: 5px;
transition: color 0.3s ease;
}
.menu li a:hover {
border-left: 3px solid white;
color: crimson;
}
.sticky .menu li a:hover {
color: white;
}
.navbar .max-width {
display: flex;
align-items: center;
justify-content: space-between;
}
.max-width {
max-width: 1300px;
padding: 0 80px;
margin: auto;
}
/*Menu Button*/
.fa.fa-bars.menuBtn {
color: #fff;
font-size: 35px;
cursor: pointer;
display: none;
}
.fa.fa-times-circle.exit {
color: white;
font-size: 35px;
cursor: pointer;
display: none;
}
#media (max-width: 934px) {
.max-width {
padding: 0 50px;
}
.fa.fa-bars.menuBtn {
display: block;
padding-left: 10em;
}
.fa.fa-times-circle.exit {
display: inline-block;
}
.menu {
position: fixed;
height: 100vh;
width: 100%;
left: 0;
top: 0;
background-color: #111;
text-align: center;
padding-top: 110px;
display: none;
}
.menu ul li {
display: block;
}
.menu ul li a {
display: inline-block;
margin: 20px 0;
font-size: 35px;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#fortawesome/fontawesome-free#5.15.3/css/fontawesome.min.css" integrity="sha384-wESLQ85D6gbsF459vf1CiZ2+rr+CsxRY0RpiF1tLlQpDnAgg6rwdsUF1+Ics2bni" crossorigin="anonymous">
<header>
<nav class="navbar" id="nav">
<div class="max-width">
<div class="logo"><a id="headSpan" href="index.html">Port<span>folio.</span></a></div>
<div class="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Skills</li>
<li>Projects</li>
<li>CV</li>
<li>Contact</li>
</ul>
</div>
<div>
<i class="fa fa-bars menuBtn" id="menuBtn" aria-hidden="true"></i>
<i class="fa fa-times-circle exit" id="exitBtn" aria-hidden="true"></i>
</div>
</div>
</nav>
<!--Head Banner-->
<section class="home" id="home">
<div class="max-width">
<div class="home-content">
<div class="text-1">Hello, my name is</div>
<div class="text-2">Hadi Zouhbi</div>
<div class="text-3">And I'm a <span id="headSpan"><Developer></Developer></span></div>
</div>
</div>
</section>
</header>
I have been asked to make horizontal navbar with a horizontal submenu as well. This behaves differently than the typical navbar, and the main issue I cannot solve is when I hover an item in the nav, it underlines and displays the submenu correctly. When I move the cursor to the submenu though, the underline disappears. I cannot figure out how to keep it underlined while mousing about the submenu.
HTML:
<!-- Beginning of Header -->
<div class='menu-container'>
<div class='menu'>
<div class='logo'>
<img
src="/images/logo.svg"
alt="Pershing's Own"
height="100"
width="150" />
</div>
<div class='calendar'>Calendar</div>
<div class='feedback'>Give Feedback</div>
<div class='tickets'><a class='red-button' href='https://www.eventbrite.com/o/the-us-army-band-pershings-own-2494510190'>Tickets</a></div>
</div>
</div>
<div class='header-container'>
<nav class='nav-container' role='navigation'>
<ul class='nav-menu'>
<li class='dropdown' tabindex='-1'>
Concerts & Events
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/event-page/event-page.html'>Concerts</a></li>
<li><a href='#'>Special Events</a></li>
<li><a href='#'>Twilight Tattoo</a></li>
<li><a href='#'>Workshops</a></li>
</ul> <!-- End of submenu -->
</li>
<li class='dropdown' tabindex='-1'>
Vacancies
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Current Openings</a></li>
<li><a href='#'>Conducting</a></li>
<li><a href='#'>Other Army Opportunities</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Watch & Listen
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Live Webcasts</a></li>
<li><a href='#'>YouTube Channel</a></li>
<li><a href='#'>Recordings</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Meet the Band
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/meet-the-band/soldiers.html'>Musicians</a></li>
<li><a href='/meet-the-band/ensembles.html'>Ensembles</a></li>
<li><a href='#'>Support Staff</a></li>
<li><a href='#'>Command Staff</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Engagement
<ul class='red-submenu'>
<li><a href='#'>Workshops</a></li>
<li><a href='#'>Competitions</a></li>
<li><a href='#'>Educational Outreach</a></li>
</ul>
</li>
</ul>
</nav>
</div>
<!-- End of Header -->
CSS:
body {
width: 1200px;
margin: 0 auto;
}
.nav-container {
color: #0C275B;
display: flex;
font-weight: 700;
justify-content: center;
}
nav {
width: 100%;
height: 75px;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-menu {
display: flex;
align-self: flex-end;
margin-bottom: 0px;
padding-left: 180px;
justify-content: space-evenly;
text-transform: uppercase;
font-size: 0.9em;
width: inherit;
}
.nav-menu a:link {
text-decoration: none;
color: #0C275B;
}
.nav-menu a:visited {
text-decoration: none;
color: #0C275B;
}
.nav-menu li {
display: inline;
padding-left: 0;
}
.nav-menu:focus {
pointer-events:none;
}
.dropdown a {
text-decoration: none;
font-size: 1em;
position: relative;
transition: all 0.6s;
}
.dropdown a:after {
content: '';
width: 0;
height: 0.3em;
position: absolute;
bottom: -5px;
left: 50%;
background: #0C275B;
transition: all 0.5s;
}
.dropdown a:hover:after {
width: 100%;
left: 0;
background: #C31F3C;
}
.red-submenu {
padding-left: 25%;
visibility: hidden;
opacity: 0;
position: absolute;
transition: all 0.5s ease;
border-top: solid white 0.5rem;
left: 0;
text-transform: none;
}
.red-submenu li {
padding-left: 80px;
}
.dropdown:active .red-submenu,
.dropdown:focus .red-submenu,
.dropdown:hover > .red-submenu,
.red-submenu:hover {
visibility: visible;
opacity: 1;
background-color: #C31F3C;
display: block;
width: 100%;
}
ul li ul li {
clear: both;
width: 100%;
}
.red-submenu a:link {
text-decoration: none;
color: #FFF;
}
.red-submenu a:visited {
text-decoration: none;
color: #FFF;
}
.red-submenu li a:hover:after {
width: 0%;
background: #C31F3C;
}
body {
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-style: normal;
font-weight: 300;
line-height: 1.8em;
color: #0C275B;
}
.menu-container {
color: #0C275B;
padding: 20px 0;
display: flex;
justify-content: center;
height: 60px;
}
.menu {
width: 100%;
display: flex;
justify-content: space-between;
font-size: 0.9em;
font-weight: 700;
}
.calendar {
margin-left: auto;
}
.feedback,
.tickets {
margin-left: 20px;
}
.tickets {
padding-right: 20px;
}
a.red-button {
color: #FFF;
background-color: #C31F3C;
font-family: 'Raleway', sans-serif;
font-weight: 700;
padding: 5px 10px 5px 10px;
height: 2.1em;
text-align: center;
border-radius: 10px;
text-decoration: none;
}
.logo {
width: 150px;
display: flex;
padding-left: 20px;
justify-content: flex-start;
}
I created a codepen here.
Menu has no JS - only HTML and CSS. If JS would solve this, that would be fine, but if there's a way to do it with just HTML and CSS, that would be preferable.
You should put the :hover on the li.dropdown element. So replace .dropdown a:hover:after with .dropdown:hover > a::after.
// Before
.dropdown a:hover:after {
width: 100%;
left: 0;
background: #C31F3C;
}
// After
.dropdown:hover > a::after {
width: 100%;
left: 0;
background: #C31F3C;
}
body {
width: 1200px;
margin: 0 auto;
}
.nav-container {
color: #0C275B;
display: flex;
font-weight: 700;
justify-content: center;
}
nav {
width: 100%;
height: 75px;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-menu {
display: flex;
align-self: flex-end;
margin-bottom: 0px;
padding-left: 180px;
justify-content: space-evenly;
text-transform: uppercase;
font-size: 0.9em;
width: inherit;
}
.nav-menu a:link {
text-decoration: none;
color: #0C275B;
}
.nav-menu a:visited {
text-decoration: none;
color: #0C275B;
}
.nav-menu li {
display: inline;
padding-left: 0;
}
.nav-menu:focus {
pointer-events:none;
}
.dropdown a {
text-decoration: none;
font-size: 1em;
position: relative;
transition: all 0.6s;
}
.dropdown a:after {
content: '';
width: 0;
height: 0.3em;
position: absolute;
bottom: -5px;
left: 50%;
background: #0C275B;
transition: all 0.5s;
}
.dropdown:hover > a::after {
width: 100%;
left: 0;
background: #C31F3C;
}
.red-submenu {
padding-left: 25%;
visibility: hidden;
opacity: 0;
position: absolute;
transition: all 0.5s ease;
border-top: solid white 0.5rem;
left: 0;
text-transform: none;
}
.red-submenu li {
padding-left: 80px;
}
.dropdown:active .red-submenu,
.dropdown:focus .red-submenu,
.dropdown:hover > .red-submenu,
.red-submenu:hover {
visibility: visible;
opacity: 1;
background-color: #C31F3C;
display: block;
width: 100%;
}
ul li ul li {
clear: both;
width: 100%;
}
.red-submenu a:link {
text-decoration: none;
color: #FFF;
}
.red-submenu a:visited {
text-decoration: none;
color: #FFF;
}
.red-submenu li a:hover:after {
width: 0%;
background: #C31F3C;
}
body {
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-style: normal;
font-weight: 300;
line-height: 1.8em;
color: #0C275B;
}
.menu-container {
color: #0C275B;
padding: 20px 0;
display: flex;
justify-content: center;
height: 60px;
}
.menu {
width: 100%;
display: flex;
justify-content: space-between;
font-size: 0.9em;
font-weight: 700;
}
.calendar {
margin-left: auto;
}
.feedback,
.tickets {
margin-left: 20px;
}
.tickets {
padding-right: 20px;
}
a.red-button {
color: #FFF;
background-color: #C31F3C;
font-family: 'Raleway', sans-serif;
font-weight: 700;
padding: 5px 10px 5px 10px;
height: 2.1em;
text-align: center;
border-radius: 10px;
text-decoration: none;
}
.logo {
width: 150px;
display: flex;
padding-left: 20px;
justify-content: flex-start;
}
<!-- Beginning of Header -->
<div class='menu-container'>
<div class='menu'>
<div class='logo'>
<img
src="/images/logo.svg"
alt="Pershing's Own"
height="100"
width="150" />
</div>
<div class='calendar'>Calendar</div>
<div class='feedback'>Give Feedback</div>
<div class='tickets'><a class='red-button' href='https://www.eventbrite.com/o/the-us-army-band-pershings-own-2494510190'>Tickets</a></div>
</div>
</div>
<div class='header-container'>
<nav class='nav-container' role='navigation'>
<ul class='nav-menu'>
<li class='dropdown' tabindex='-1'>
Concerts & Events
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/event-page/event-page.html'>Concerts</a></li>
<li><a href='#'>Special Events</a></li>
<li><a href='#'>Twilight Tattoo</a></li>
<li><a href='#'>Workshops</a></li>
</ul> <!-- End of submenu -->
</li>
<li class='dropdown' tabindex='-1'>
Vacancies
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Current Openings</a></li>
<li><a href='#'>Conducting</a></li>
<li><a href='#'>Other Army Opportunities</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Watch & Listen
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='#'>Live Webcasts</a></li>
<li><a href='#'>YouTube Channel</a></li>
<li><a href='#'>Recordings</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Meet the Band
<ul class='red-submenu'> <!-- Start of submenu -->
<li><a href='/meet-the-band/soldiers.html'>Musicians</a></li>
<li><a href='/meet-the-band/ensembles.html'>Ensembles</a></li>
<li><a href='#'>Support Staff</a></li>
<li><a href='#'>Command Staff</a></li>
</ul>
</li>
<li class='dropdown' tabindex='-1'>
Engagement
<ul class='red-submenu'>
<li><a href='#'>Workshops</a></li>
<li><a href='#'>Competitions</a></li>
<li><a href='#'>Educational Outreach</a></li>
</ul>
</li>
</ul>
</nav>
</div>
<!-- End of Header -->
<!-- Begin main section -->
<div class='main-container'>
</div>