How to keep focus on a custom dropdown after making selection? - html

I have a custom dropdown and I've set up focus states on the dropdown and the items in it. But, when I select an item from the first menu, the focus goes to the nav and not the next dropdown. Is there a way to target the second dropdown after the first one?
Here's a Codepen if you'd prefer.
for (const dropdown of document.querySelectorAll(".custom__select-wrapper:not(.clearFilter)")) {
dropdown.addEventListener("click", function () {
this.querySelector(".custom__select").classList.toggle("open");
});
}
for (const option of document.querySelectorAll(".custom__option")) {
option.addEventListener("click", function () {
if (!this.classList.contains("selected")) {
this.parentNode
.querySelector(".custom__option.selected")
.classList.remove("selected");
this.classList.add("selected");
this.closest(".custom__select").querySelector(
".custom__select-trigger h6"
).textContent = this.textContent;
if (this.getAttribute("data-type")) {
current_story = this.dataset["type"];
}
}
});
}
window.addEventListener("click", function (e) {
for (const select of document.querySelectorAll(".custom__select")) {
if (!select.contains(e.target)) {
select.classList.remove("open");
}
}
});
#charset "UTF-8";
nav ul {
list-style-type: none;
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-evenly;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
}
button.clear {
border: 0;
background: #fff;
}
#selectedFilter {
color: #005fec;
}
ul {
padding-left: 0;
margin: 0;
}
.filter {
padding-right: 15px;
padding-left: 15px;
margin-bottom: 2rem;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.filter__settings {
display: flex;
flex-direction: row;
border-top: 1px solid #E0E5EC;
border-bottom: 1px solid #E0E5EC;
}
}
.custom__select {
position: relative;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.custom::before, .custom__options {
transition: all 0.2s ease-in;
}
}
.custom__select-wrapper {
position: relative;
user-select: none;
padding: 0;
border-bottom: 1px solid #E0E5EC;
}
.custom__select-wrapper:last-child {
border: 0;
}
.custom__select-wrapper.clearFilter {
display: flex;
flex-direction: column;
justify-content: center;
}
.custom__select-wrapper .selected-clearFilter {
position: relative;
user-select: none;
padding: 1rem 0 !important;
}
#media (min-width: 768px) {
.custom__select-wrapper {
padding: 0 2em;
border: 0;
display: flex;
justify-content: center;
align-items: center;
}
.custom__select-wrapper:first-child, .custom__select-wrapper:last-child {
padding: 0;
}
}
.custom__select-wrapper h6 {
padding: 20px 3px;
color: #62668C;
font-weight: 300;
}
.custom__select-trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
#media (min-width: 768px) {
.custom__select-trigger {
justify-content: space-evenly;
margin-right: auto;
}
}
.custom__select-wrapper h6, .custom__select-trigger h6 {
font-size: 0.75rem;
line-height: 0.75rem;
letter-spacing: 1px;
text-transform: uppercase;
padding: 20px 0;
}
.custom__select-trigger h6 {
color: #005fec;
font-weight: 900;
}
.custom__select-wrapper #selectedFilter {
font-size: 12px;
line-height: 12px;
letter-spacing: 1px;
text-transform: uppercase;
color: #005fec;
font-weight: 800;
padding: 0;
}
.custom__options {
display: none;
top: 100%;
left: 0;
right: 0;
border-top: 0;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
color: #E0E5EC;
}
#media (min-width: 768px) {
.custom__options {
display: unset;
position: absolute;
background-color: #005fec;
max-height: 320px;
overflow-y: scroll;
}
.custom__options#storyFilter {
overflow: hidden;
}
}
.custom__options.active {
display: block;
visibility: visible;
opacity: 1;
z-index: 10;
}
.custom__select-trigger, .custom__option {
letter-spacing: 1px;
font-weight: 800;
color: #005fec;
border: 0;
background: transparent;
}
#media (min-width: 768px) {
.custom__select.open::before {
content: "";
position: absolute;
bottom: 0;
left: 11px;
border-left: 11px solid transparent;
border-right: 11px solid transparent;
border-bottom: 11px solid #005fec;
}
}
.custom__select .custom__options {
min-width: 15rem;
}
.custom__select.open .custom__options {
display: block;
opacity: 1;
visibility: visible;
pointer-events: all;
color: #fff;
min-width: 15rem;
}
#media (min-width: 768px) {
.custom__select.open .custom__options {
display: unset;
box-shadow: 0px 12px 30px rgba(0, 0, 0, 0.12);
}
}
.custom__option {
position: relative;
display: block;
padding: 0 22px 0 12px;
font-weight: 400;
color: #62668C;
cursor: pointer;
font-size: 1rem;
line-height: 1rem;
margin: 1.5rem 0;
}
#media (min-width: 768px) {
.custom__option {
font-size: 1.25rem;
line-height: 1.25rem;
color: white;
font-weight: 300;
padding: 0 22px 0 20px;
}
.custom__option a {
color: white !important;
text-decoration: none;
}
}
.custom__option:hover {
cursor: pointer;
}
.custom__option.selected {
color: #005fec;
}
#media (min-width: 768px) {
.custom__option.selected {
color: #ffffff;
}
}
.custom__option.selected::before {
content: "•";
margin-left: -12px;
padding-right: 8px;
}
.empty-state {
width: 100%;
display: flex;
background: #005fec;
padding: 1rem;
border-radius: 4px;
align-items: center;
margin: 2rem 0.5rem;
}
.empty-state h4 {
color: white;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 300;
margin-left: 0.5rem;
}
.empty-state h4 span {
color: white;
text-decoration: underline;
cursor: pointer;
}
.arrow {
position: relative;
height: 5px;
width: 3px;
margin-left: 0.5rem;
margin-bottom: 0.1rem;
}
.arrow::before, .arrow::after {
content: "";
position: absolute;
bottom: 0px;
width: 0.1rem;
height: 100%;
transition: all 0.45s;
}
.arrow::before {
left: 0px;
transform: rotate(45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::before {
left: 7px;
}
}
.arrow::after {
left: -2.5px;
transform: rotate(-45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::after {
left: 4.5px;
}
}
.open .arrow::before {
left: 0px;
transform: rotate(-45deg);
}
#media (min-width: 768px) {
.open .arrow::before {
left: 7px;
}
}
.open .arrow::after {
left: -2.5px;
transform: rotate(45deg);
}
#media (min-width: 768px) {
.open .arrow::after {
left: 4.5px;
}
}
<div class="container">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Sales</li>
<li>Contact</li>
</ul>
</nav>
<section class="content">
<h2 class="title">Hello World</h2>
<h6 class="subtitle">Lorem ipsum dolor sit amet.</h6>
</section>
<section class="filter">
<div class="filter__settings">
<div class="custom__select-wrapper">
<h6>filter by</h6>
</div>
<div class="custom__select-wrapper">
<div class="custom__select story-sel selector" role="menubar">
<button class="custom__select-trigger" aria-haspopup="true" aria-expanded="false" id="storySelector">
<h6>Story Type</h6>
<div class="arrow"></div>
</button>
<ul class="custom__options dropdown story-selector" id="storyFilter" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-type="all" id="storyItem_all">All
</li>
<li role="menuitem" class="custom__option" data-type="news" id="storyItem_nm"><a href="#">News and
media</a></li>
<li role="menuitem" class="custom__option" data-type="analysis" id="storyItem_analysis">Analysis</li>
<li role="menuitem" class="custom__option" data-type="press" id="storyItem_pr"><a href="#">Press
releases</a></li>
</ul>
</div>
</div>
<div class="custom__select-wrapper">
<div class="custom__select year-sel selector">
<button type="button" class="custom__select-trigger" id="yearSelector">
<h6>Year</h6>
<div class=" arrow"></div>
</button>
<ul class="custom__options dropdown year-selector" id="yearSelection" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-year="all">All</li>
<li role="menuitem" class="custom__option" data-year="2021">2021</li>
<li role="menuitem" class="custom__option" data-year="2020">2020</li>
<li role="menuitem" class="custom__option" data-year="2019">2019</li>
</ul>
</div>
</div>
</div>
</section>
</div>

The problem lies in your anchor tags. Specifically, setting the href attribute to # will cause the page to jump to the top.
From MDN:
You can use href="#top" or the empty fragment (href="#") to link to the top of the current page, as defined in the HTML specification.
In your case, simply remove the href attribute. If you want to preserve navigation with the keyboard, set it to "javascript:void(0)"
for (const dropdown of document.querySelectorAll(".custom__select-wrapper:not(.clearFilter)")) {
dropdown.addEventListener("click", function () {
this.querySelector(".custom__select").classList.toggle("open");
});
}
for (const option of document.querySelectorAll(".custom__option")) {
option.addEventListener("click", function () {
if (!this.classList.contains("selected")) {
this.parentNode
.querySelector(".custom__option.selected")
.classList.remove("selected");
this.classList.add("selected");
this.closest(".custom__select").querySelector(
".custom__select-trigger h6"
).textContent = this.textContent;
if (this.getAttribute("data-type")) {
current_story = this.dataset["type"];
}
}
});
}
window.addEventListener("click", function (e) {
for (const select of document.querySelectorAll(".custom__select")) {
if (!select.contains(e.target)) {
select.classList.remove("open");
}
}
});
#charset "UTF-8";
nav ul {
list-style-type: none;
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-evenly;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
}
button.clear {
border: 0;
background: #fff;
}
#selectedFilter {
color: #005fec;
}
ul {
padding-left: 0;
margin: 0;
}
.filter {
padding-right: 15px;
padding-left: 15px;
margin-bottom: 2rem;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.filter__settings {
display: flex;
flex-direction: row;
border-top: 1px solid #E0E5EC;
border-bottom: 1px solid #E0E5EC;
}
}
.custom__select {
position: relative;
display: flex;
flex-direction: column;
}
#media (min-width: 768px) {
.custom::before, .custom__options {
transition: all 0.2s ease-in;
}
}
.custom__select-wrapper {
position: relative;
user-select: none;
padding: 0;
border-bottom: 1px solid #E0E5EC;
}
.custom__select-wrapper:last-child {
border: 0;
}
.custom__select-wrapper.clearFilter {
display: flex;
flex-direction: column;
justify-content: center;
}
.custom__select-wrapper .selected-clearFilter {
position: relative;
user-select: none;
padding: 1rem 0 !important;
}
#media (min-width: 768px) {
.custom__select-wrapper {
padding: 0 2em;
border: 0;
display: flex;
justify-content: center;
align-items: center;
}
.custom__select-wrapper:first-child, .custom__select-wrapper:last-child {
padding: 0;
}
}
.custom__select-wrapper h6 {
padding: 20px 3px;
color: #62668C;
font-weight: 300;
}
.custom__select-trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
#media (min-width: 768px) {
.custom__select-trigger {
justify-content: space-evenly;
margin-right: auto;
}
}
.custom__select-wrapper h6, .custom__select-trigger h6 {
font-size: 0.75rem;
line-height: 0.75rem;
letter-spacing: 1px;
text-transform: uppercase;
padding: 20px 0;
}
.custom__select-trigger h6 {
color: #005fec;
font-weight: 900;
}
.custom__select-wrapper #selectedFilter {
font-size: 12px;
line-height: 12px;
letter-spacing: 1px;
text-transform: uppercase;
color: #005fec;
font-weight: 800;
padding: 0;
}
.custom__options {
display: none;
top: 100%;
left: 0;
right: 0;
border-top: 0;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
color: #E0E5EC;
}
#media (min-width: 768px) {
.custom__options {
display: unset;
position: absolute;
background-color: #005fec;
max-height: 320px;
overflow-y: scroll;
}
.custom__options#storyFilter {
overflow: hidden;
}
}
.custom__options.active {
display: block;
visibility: visible;
opacity: 1;
z-index: 10;
}
.custom__select-trigger, .custom__option {
letter-spacing: 1px;
font-weight: 800;
color: #005fec;
border: 0;
background: transparent;
}
#media (min-width: 768px) {
.custom__select.open::before {
content: "";
position: absolute;
bottom: 0;
left: 11px;
border-left: 11px solid transparent;
border-right: 11px solid transparent;
border-bottom: 11px solid #005fec;
}
}
.custom__select .custom__options {
min-width: 15rem;
}
.custom__select.open .custom__options {
display: block;
opacity: 1;
visibility: visible;
pointer-events: all;
color: #fff;
min-width: 15rem;
}
#media (min-width: 768px) {
.custom__select.open .custom__options {
display: unset;
box-shadow: 0px 12px 30px rgba(0, 0, 0, 0.12);
}
}
.custom__option {
position: relative;
display: block;
padding: 0 22px 0 12px;
font-weight: 400;
color: #62668C;
cursor: pointer;
font-size: 1rem;
line-height: 1rem;
margin: 1.5rem 0;
}
#media (min-width: 768px) {
.custom__option {
font-size: 1.25rem;
line-height: 1.25rem;
color: white;
font-weight: 300;
padding: 0 22px 0 20px;
}
.custom__option a {
color: white !important;
text-decoration: none;
}
}
.custom__option:hover {
cursor: pointer;
}
.custom__option.selected {
color: #005fec;
}
#media (min-width: 768px) {
.custom__option.selected {
color: #ffffff;
}
}
.custom__option.selected::before {
content: "•";
margin-left: -12px;
padding-right: 8px;
}
.empty-state {
width: 100%;
display: flex;
background: #005fec;
padding: 1rem;
border-radius: 4px;
align-items: center;
margin: 2rem 0.5rem;
}
.empty-state h4 {
color: white;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 300;
margin-left: 0.5rem;
}
.empty-state h4 span {
color: white;
text-decoration: underline;
cursor: pointer;
}
.arrow {
position: relative;
height: 5px;
width: 3px;
margin-left: 0.5rem;
margin-bottom: 0.1rem;
}
.arrow::before, .arrow::after {
content: "";
position: absolute;
bottom: 0px;
width: 0.1rem;
height: 100%;
transition: all 0.45s;
}
.arrow::before {
left: 0px;
transform: rotate(45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::before {
left: 7px;
}
}
.arrow::after {
left: -2.5px;
transform: rotate(-45deg);
background-color: #005fec;
}
#media (min-width: 768px) {
.arrow::after {
left: 4.5px;
}
}
.open .arrow::before {
left: 0px;
transform: rotate(-45deg);
}
#media (min-width: 768px) {
.open .arrow::before {
left: 7px;
}
}
.open .arrow::after {
left: -2.5px;
transform: rotate(45deg);
}
#media (min-width: 768px) {
.open .arrow::after {
left: 4.5px;
}
}
<div class="container">
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Sales</li>
<li>Contact</li>
</ul>
</nav>
<section class="content">
<h2 class="title">Hello World</h2>
<h6 class="subtitle">Lorem ipsum dolor sit amet.</h6>
</section>
<section class="filter">
<div class="filter__settings">
<div class="custom__select-wrapper">
<h6>filter by</h6>
</div>
<div class="custom__select-wrapper">
<div class="custom__select story-sel selector" role="menubar">
<button class="custom__select-trigger" aria-haspopup="true" aria-expanded="false" id="storySelector">
<h6>Story Type</h6>
<div class="arrow"></div>
</button>
<ul class="custom__options dropdown story-selector" id="storyFilter" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-type="all" id="storyItem_all">All
</li>
<li role="menuitem" class="custom__option" data-type="news" id="storyItem_nm"><a href="javascript:void(0);">News and
media</a></li>
<li role="menuitem" class="custom__option" data-type="analysis" id="storyItem_analysis">Analysis</li>
<li role="menuitem" class="custom__option" data-type="press" id="storyItem_pr"><a href="javascript:void(0);">Press
releases</a></li>
</ul>
</div>
</div>
<div class="custom__select-wrapper">
<div class="custom__select year-sel selector">
<button type="button" class="custom__select-trigger" id="yearSelector">
<h6>Year</h6>
<div class=" arrow"></div>
</button>
<ul class="custom__options dropdown year-selector" id="yearSelection" aria-label="submenu" role="menu" aria-labelledby="custom-dropdown">
<li role="menuitem" class="custom__option selected" data-year="all">All</li>
<li role="menuitem" class="custom__option" data-year="2021">2021</li>
<li role="menuitem" class="custom__option" data-year="2020">2020</li>
<li role="menuitem" class="custom__option" data-year="2019">2019</li>
</ul>
</div>
</div>
</div>
</section>
</div>

Related

Bootstrap v5.0.1 - Hamburger menu not auto closing when clicking same page anchor links - Responsive

Dear stackoverflow community,
For some odd reason I can't figure out why the hamburger menu when responsive or non responsive if collapse is enabled doesn't auto close when clicking on same page anchor links. Can someone point me to the right direction or have a solution for this? I am using Bootstrap v5.0.1.
Here is the CSS CODE:
& when not (#sticky) {
.navbar-dropdown {
position: relative !important;
}
& when (#transparent) {
.navbar-dropdown {
position: absolute !important;
}
}
}
& when (#sticky) {
z-index: 1000;
width: 100%;
& when not (#transparent) {
position: relative;
min-height: 60px;
}
nav.navbar {
position: fixed;
}
}
.dropdown-item:before {
font-family: Moririse2 !important;
content: "\e966";
display: inline-block;
width: 0;
position: absolute;
left: 1rem;
top: 0.5rem;
margin-right: 0.5rem;
line-height: 1;
font-size: inherit;
vertical-align: middle;
text-align: center;
overflow: hidden;
transform: scale(0, 1);
transition: all 0.25s ease-in-out;
}
.dropdown-menu {
padding: 0;
border-radius: 4px;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}
.dropdown-item {
border-bottom: 1px solid #e6e6e6;
&:hover, &:focus {
background: #primaryColor !important;
color: white !important;
}
&:hover span {
color: white;
}
&:first-child {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
&:last-child {
border-bottom: none;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}
}
.nav-dropdown .link {
padding: 0 0.3em !important;
margin: 0.667em 1em !important;
}
.nav-dropdown .link.dropdown-toggle::after {
margin-left: 0.5rem;
margin-top: 0.2rem;
}
.nav-link {
position: relative;
}
.container {
display: flex;
margin: auto;
flex-wrap: nowrap;
#media (max-width: 991px) {
flex-wrap: wrap;
}
& when (#collapsed) {
flex-wrap: wrap;
}
}
.container-fluid {
flex-wrap: nowrap;
#media (max-width: 991px) {
flex-wrap: wrap;
}
& when (#collapsed) {
flex-wrap: wrap;
}
}
.iconfont-wrapper {
color: #iconsColor !important;
font-size: 1.5rem;
padding-right: 0.5rem;
}
.navbar-caption {
}
.navbar-nav {
}
.dropdown-menu, .navbar.opened {
background: #menuBgColor !important;
}
.nav-item:focus, .nav-link:focus {
outline: none;
}
.dropdown .dropdown-menu .dropdown-item {
width: auto;
transition: all 0.25s ease-in-out;
&::after {
right: 0.5rem;
}
.mbr-iconfont {
margin-right: 0.5rem;
vertical-align: sub;
&:before {
display: inline-block;
transform: scale(1, 1);
transition: all 0.25s ease-in-out;
}
}
}
.collapsed {
.dropdown-menu .dropdown-item:before {
display: none;
}
.dropdown .dropdown-menu .dropdown-item {
padding: 0.235em 1.5em 0.235em 1.5em !important;
transition: none;
margin: 0 !important;
}
}
.navbar {
min-height: 70px;
transition: all 0.3s;
border-bottom: 1px solid transparent;
&:not(.navbar-short) {
}
& when not (#transparent) {
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
background: #menuBgColor;
}
& when (#transparent) {
background: rgba(red(#menuBgColor), green(#menuBgColor), blue(#menuBgColor), #opacity);
}
&.opened {
transition: all 0.3s;
}
.dropdown-item {
padding: 0.5rem 1.8rem;
}
.navbar-logo img {
width: auto;
}
.navbar-collapse {
justify-content: flex-end;
z-index: 1;
}
&.collapsed {
justify-content: center;
.nav-item .nav-link::before {
display: none;
}
&.opened {
.dropdown-menu {
top: 0;
}
#media (min-width: 992px) {
&:not(.navbar-short) .navbar-collapse when (#showLogo) {
max-height: ~"calc(98.5vh - #{logoSize}rem)";
}
}
}
.dropdown-menu {
.dropdown-submenu {
left: 0 !important;
}
.dropdown-item:after {
right: auto;
}
.dropdown-toggle[data-toggle="dropdown-submenu"]:after {
margin-left: 0.5rem;
margin-top: 0.2rem;
border-top: 0.35em solid;
border-right: 0.35em solid transparent;
border-left: 0.35em solid transparent;
border-bottom: 0;
top: 41%;
}
}
ul.navbar-nav {
li {
margin: auto;
}
}
.dropdown-menu .dropdown-item {
padding: 0.25rem 1.5rem;
text-align: center;
}
.icons-menu {
padding-left: 0;
padding-right: 0;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
}
#media (max-width: 991px) {
.nav-item .nav-link::before {
display: none;
}
&.opened {
.dropdown-menu {
top: 0;
}
}
.dropdown-menu {
.dropdown-submenu {
left: 0 !important;
}
.dropdown-item:after {
right: auto;
}
.dropdown-toggle[data-toggle="dropdown-submenu"]:after {
margin-left: 0.5rem;
margin-top: 0.2rem;
border-top: 0.35em solid;
border-right: 0.35em solid transparent;
border-left: 0.35em solid transparent;
border-bottom: 0;
top: 40%;
}
}
.navbar-logo {
img {
height: 3rem !important;
}
}
ul.navbar-nav {
li {
margin: auto;
}
}
.dropdown-menu .dropdown-item {
padding: 0.25rem 1.5rem !important;
text-align: center;
}
.navbar-brand {
flex-shrink: initial;
flex-basis: auto;
word-break: break-word;
padding-right: 2rem;
#media (max-width: 767px) {
width: ~"calc(100% - 31px)";
}
}
.navbar-toggler {
flex-basis: auto;
}
.icons-menu {
padding-left: 0;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
}
&.navbar-short {
min-height: 60px;
.navbar-logo {
img {
height: 2.5rem !important;
}
}
.navbar-brand {
min-height: 60px;
padding: 0;
}
}
}
.navbar-brand {
min-height: 70px;
flex-shrink: 0;
align-items: center;
margin-right: 0;
padding: 10px 0;
transition: all 0.3s;
word-break: break-word;
z-index: 1;
.navbar-caption {
line-height: inherit !important;
}
.navbar-logo a {
outline: none;
}
}
.dropdown-item.active, .dropdown-item:active {
background-color: transparent;
}
.navbar-expand-lg .navbar-nav .nav-link {
padding: 0;
}
.nav-dropdown .link.dropdown-toggle {
margin-right: 1.667em;
&[aria-expanded="true"] {
margin-right: 0;
padding: 0.667em 1.667em;
}
}
.navbar.navbar-expand-lg .dropdown {
.dropdown-menu {
background: #menuBgColor;
.dropdown-submenu {
margin: 0;
left: 100%;
}
}
}
.navbar .dropdown.open > .dropdown-menu {
display: block;
}
ul.navbar-nav {
flex-wrap: wrap;
}
.navbar-buttons {
text-align: center;
min-width: 170px;
}
button.navbar-toggler {
outline: none;
width: 31px;
height: 20px;
cursor: pointer;
transition: all 0.2s;
position: relative;
align-self: center;
.hamburger span {
position: absolute;
right: 0;
width: 30px;
height: 2px;
border-right: 5px;
background-color: #hamburgerColor;
&:nth-child(1) {
top: 0;
transition: all 0.2s;
}
&:nth-child(2) {
top: 8px;
transition: all 0.15s;
}
&:nth-child(3) {
top: 8px;
transition: all 0.15s;
}
&:nth-child(4) {
top: 16px;
transition: all 0.2s;
}
}
}
nav.opened .hamburger span {
&:nth-child(1) {
top: 8px;
width: 0;
opacity: 0;
right: 50%;
transition: all 0.2s;
}
&:nth-child(2) {
transform: rotate(45deg);
transition: all 0.25s;
}
&:nth-child(3) {
transform: rotate(-45deg);
transition: all 0.25s;
}
&:nth-child(4) {
top: 8px;
width: 0;
opacity: 0;
right: 50%;
transition: all 0.2s;
}
}
.navbar-dropdown {
padding: 0 1rem;
& when (#sticky) {
position: fixed;
}
}
a.nav-link {
display: flex;
align-items: center;
justify-content: center;
}
.icons-menu {
flex-wrap: nowrap;
display: flex;
justify-content: center;
padding-left: 1rem;
padding-right: 1rem;
padding-top: 0.3rem;
text-align: center;
}
#media screen and (~'-ms-high-contrast: active'), (~'-ms-high-contrast: none') {
.navbar {
height: 70px;
&.opened {
height: auto;
}
}
.nav-item .nav-link:hover::before {
width: 175%;
max-width: calc(100% ~"+" 2rem);
left: -1rem;
}
}
Here is the HTML code:
<section data-bs-version="5.1" class="menu menu3 cid-tsEnTljTpk" once="menu" id="menu3-0">
<nav class="navbar navbar-dropdown navbar-fixed-top navbar-expand-lg">
<div class="container">
<div class="navbar-brand">
<span class="navbar-logo">
<a href="#">
<img src="assets/images/mbr.png" alt="" style="height: 4rem;">
</a>
</span>
<span class="navbar-caption-wrap"><a class="navbar-caption text-black display-7" href="#">Temperature Experts</a></span>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-bs-toggle="collapse" data-target="#navbarSupportedContent" data-bs-target="#navbarSupportedContent" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<div class="hamburger">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav nav-dropdown" data-app-modern-menu="true"><li class="nav-item"><a class="nav-link link text-black text-primary display-4" href="index.html#Who-We-Are">
About us</a></li>
<li class="nav-item"><a class="nav-link link text-black text-primary display-4" href="index.html#Our_Services">
Services</a></li>
<li class="nav-item"><a class="nav-link link text-black display-4" href="#">Contacts</a>
</li></ul>
<div class="icons-menu">
<a class="iconfont-wrapper" href="#" target="_blank">
<span class="p-2 mbr-iconfont socicon-facebook socicon"></span>
</a>
<a class="iconfont-wrapper" href="#" target="_blank">
<span class="p-2 mbr-iconfont socicon-twitter socicon"></span>
</a>
<a class="iconfont-wrapper" href="#" target="_blank">
<span class="p-2 mbr-iconfont socicon-instagram socicon"></span>
</a>
<a class="iconfont-wrapper" href="#" target="_blank">
<span class="p-2 mbr-iconfont socicon-youtube socicon"></span>
</a>
</div>
<div class="navbar-buttons mbr-section-btn"><a class="btn btn-primary display-4" href="tel:1-800-test-test">Call Now</a></div>
</div>
</div>
</nav>
</section>

Overflow issue with burger menu

I'm trying to learn how to create burger menus for the mobile version of the site. I've managed to create a simple burger-menu with a little help of js, but I faced the problem with overflow. Burger works fine, but it has a sidescroll when it's unactive. I understand that it could be fixed with position: relative and overflow: hidden, but I can't figure out to which block I should apply those parameters. When I try to apply this parameters to the parent header block, burger menu becomes the header's hight. Can't really understand how to avoid it.
HTML:
`<header class="header">
<div class="header__container">
<a href="#"
><div class="logo__block">
<img src="img/logo.svg" alt="Logo" /></div
></a>
<nav class="header__nav nav">
<ul class="nav__list">
<div class="burger-menu__exit">X</div>
<li class="nav__item">
Home
</li>
<li class="nav__item">
Features
</li>
<li class="nav__item">
Pricing
</li>
<li class="nav__item">
Blog
</li class="nav__item nav-btn">
</ul>
</nav>
<a class="header-btn" href="#">Get Started</a>
<div class="burger-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
</div>
</header>`
CSS:
`body {
font-family: "Libre Franklin", sans-serif;
}
[class$="__container"] {
max-width: 1270px;
margin: 0 auto;
padding: 0 15px;
}
.header__container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
line-height: 60px;
padding-top: 40px;
padding-bottom: 60px;
}
.header__container:before{
position: relative;
}
.logo__block {
display: flex;
align-items: center;
}
.nav {
margin-left: auto;
}
.nav__list {
display: flex;
flex-direction: row;
justify-content: flex-end;
}
.nat__item {
}
.nav-btn {
display: none;
}
.nav__list > li:not(.nav__item:last-child) {
margin-right: 100px;
}
.nav__item:last-child {
margin-right: 79px;
}
.nav__link {
font-style: normal;
font-weight: 400;
font-size: 20px;
}
.nav__link:hover {
border-bottom: 2px solid black;
}
.btn__block {
max-width: 286px;
}
.header-btn {
width: 211px;
text-align: center;
border-radius: 10px;
font-style: normal;
font-weight: 500;
font-size: 20px;
color: white;
background-color: #ff7143;
transition: 0.3s;
}
.header-btn:hover {
background-color: #d1542b;
}
.burger-menu {
display: none;
margin-left: 10px;
cursor: pointer;
}
.burger-menu__exit {
display: none;
}
.line {
width: 35px;
height: 2px;
background-color: black;
margin-top: 10px;
}
.line1 {
margin-top: 0;
}
#media (max-width: 1309px) {
[class$="__container"] {
max-width: 1103px;
}
}
#media (max-width: 1129px) {
[class$="__container"] {
max-width: 1000px;
}
.nav__list > li:not(.nav__item:last-child) {
margin-right: 50px;
}
.nav__item:last-child {
margin-right: 79px;
}
}
#media (max-width: 988.98px) {
[class$="__container"] {
max-width: none;
}
.burger-menu {
display: block;
}
.header__nav {
background-color: #5454d4;
z-index: 9999;
}
.nav {
position: absolute;
top: 0;
left: 100%;
right: -100%;
z-index: 999;
min-width: 375px;
height: 100vh;
padding-top: 30px;
color: #ff7143;
transition: 1s;
}
.nav__list {
position: relative;
flex-direction: column;
align-items: center;
justify-content: center;
}
.nav__list a {
color: #ff7143;
}
.nav__list a:hover {
border-bottom: 2px solid #ff7143;
}
.nav__list > li:not(.nav__item:last-child) {
margin-right: 0;
}
.nav__item:last-child {
margin-right: 0;
}
.header-btn {
margin-left: auto;
}
.burger-menu__exit {
display: block;
cursor: pointer;
position: absolute;
top: 0;
right: 18px;
font-size: 40px;
}
}
#media (max-width: 512.98px) {
.header-btn {
display: none;
}
}
#media (max-width: 369.98px) {
.nav {
min-width: 100%;
}
}`
JS:
const mobileNav = document.querySelector(".nav");
const headerButton = document.querySelector(".header-btn");
const headerContainer = document.querySelector(".header__container");
document.querySelector(".burger-menu").addEventListener("click", () => {
mobileNav.style.right = 0;
});
document.querySelector(".burger-menu__exit").addEventListener("click", () => {
mobileNav.style.right = -100 + "%";
});
Thanks for the help!
Issue was fixed by adding the different navigation for burger outside the header block and adding the position: relative; overflow: hidden; to the html and body.

Footer and Form appearing into each other

While developing my website I have came across a problem with my footer and form. My footer seems to be appearing through the form on devices but not on the computer and I'm sure this could be issues with widths of devices? So I kept trying to fix it and still haven't been able to fix it. I'm still learning as I go along and I would be grateful if someone could help me get rolling with my website again. code snippets and images below, kindest regards, Caelan.
body {
background-color: black ;
}
/* Announcment bar */
.alert {
padding: 20px;
background-color: #2a7a85;
color: white;
}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
body {
margin: 0;
}
/* Navigation bar */
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(248, 248, 248);
}
ul.topnav li {
float: left;
}
ul.topnav li a {
display: block;
color: black;
text-align: center;
font-weight: bold;
padding: 25px 32px;
text-decoration: none;
}
ul.topnav li a:hover:not(.active) {
background-color: rgb(55, 81, 165);
}
ul.topnav li a.active {
background-color: #0cc0d8;
}
ul.topnav li.right {
float: right;
}
#media screen and (max-width: 600px) {
ul.topnav li.right,
ul.topnav li {
float: none;
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.text {
font-size: 11px;
}
}
/* Homepage button */
.glow-on-hover {
width: 220px;
height: 35px;
border: none;
outline: none;
color: rgb(0, 0, 0);
font-weight: bold;
font-size: 20px;
background: #111;
cursor: pointer;
position: relative;
z-index: 0;
border-radius: 10px;
}
.glow-on-hover:before {
content: '';
background: linear-gradient(45deg, #ff0000, #ff7300, #fffb00, #48ff00, #00ffd5, #002bff, #7a00ff, #ff00c8, #ff0000);
position: absolute;
top: -2px;
left:-2px;
background-size: 400%;
z-index: -1;
filter: blur(5px);
width: calc(100% + 4px);
height: calc(100% + 4px);
animation: glowing 20s linear infinite;
opacity: 0;
transition: opacity .3s ease-in-out;
border-radius: 10px;
}
.glow-on-hover:active {
color: #000
}
.glow-on-hover:active:after {
background: transparent;
}
.glow-on-hover:hover:before {
opacity: 1;
}
.glow-on-hover:after {
z-index: -1;
content: '';
position: absolute;
width: 100%;
height: 100%;
background: rgb(11, 78, 223);
left: 0;
top: 0;
border-radius: 10px;
}
#keyframes glowing {
0% { background-position: 0 0; }
50% { background-position: 400% 0; }
100% { background-position: 0 0; }
}
/* kipplo heading on homepage */
h1 {
font-size: 10vw;
margin: 0;
padding: 0;
font-family: 'Courier New', Courier, monospace;
color: blue;
word-wrap: break-word;
text-align: center;
}
/* for the heading and the button alignment*/
.container {
display: flex;
flex-direction: column;
height: 100vh;
}
.btn-centering {
flex-grow: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* product cards*/
h3{
text-align: center;
font-size: 30px;
margin: 0;
padding-top: 10px;
}
a{
text-decoration: none;
}
.gallery{
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: center;
align-items: center;
margin: 50px 0;
}
.content{
width: 24%;
margin: 15px;
box-sizing: border-box;
float: left;
text-align: center;
border-radius:10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
padding-top: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: .4s;
background-color: whitesmoke;
}
.content:hover{
box-shadow: 0 0 11px rgb(0, 217, 255);
transform: translate(0px, -8px);
transition: .6s;
}
.productcard-image{
width: 200px;
height: 200px;
text-align: center;
margin: 0 auto;
display: block;
}
p{
text-align: center;
color: #b2bec3;
padding: 0 8px;
}
h6{
font-size: 26px;
text-align: center;
color: #222f3e;
margin: 0;
}
.product-card{
list-style-type: none;
display: flex;
justify-content: center;
align-items: center;
padding: 0px;
}
.productcard-list{
padding: 5px;
}
.fa{
color: #ff9f43;
font-size: 26px;
transition: .4s;
}
.fa:hover{
transform: scale(1.3);
transition: .6s;
}
.productcardbutton{
text-align: center;
font-size: 24px;
color: #fff;
width: 100%;
padding: 15px;
border:0px;
outline: none;
cursor: pointer;
margin-top: 5px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
.buy-1{
background-color: #2183a2;
}
.buy-2{
background-color: #3b3e6e;
}
.buy-3{
background-color: #0b0b0b;
}
#media(max-width: 1000px){
.content{
width: 46%;
}
}
#media(max-width: 750px){
.content{
width: 100%;
}
}
/* Footer */
.footer__container {
background-color: #141414;
padding: 5rem 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#footer__logo {
color: #fff;
display: flex;
align-items: center;
cursor: pointer;
text-decoration: none;
font-size: 2rem;
}
.footer__links {
width: 100%;
max-width: 1000px;
display: flex;
justify-content: center;
}
.footer__link--wrapper {
display: flex;
}
.footer__link--items {
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 16px;
text-align: left;
width: 160px;
box-sizing: border-box;
}
.footer__link--items h2 {
margin-bottom: 16px;
}
.footer__link--items > h2 {
color: #fff;
}
.footer__link--items a {
color: #fff;
text-decoration: none;
margin-bottom: 0.5rem;
}
.footer__link--items a:hover {
color: #e9e9e9;
transition: 0.3s ease-out;
}
/* Social Icons */
.social__icon--link {
color: #fff;
font-size: 24px;
}
.social__media {
max-width: 1000px;
width: 100%;
}
.social__media--wrap {
display: flex;
justify-content: space-between;
align-items: center;
width: 90%;
max-width: 1000px;
margin: 40px auto 0 auto;
}
.website__rights {
color: #fff;
}
#media screen and (max-width: 820px) {
.footer__links {
padding-top: 2rem;
}
#footer__logo {
margin-bottom: 2rem;
}
.website__rights {
padding: 2rem;
}
.footer__link--wrapper {
flex-direction: column;
}
.social__media--wrap {
flex-direction: column;
}
}
#media screen and (max-width: 480px) {
.footer__link--items {
margin: 0;
padding: 10px;
width: 100%;
}
}
/* Text above the form*/
/* Feedback form*/
.form1 {
display: flex;
flex-direction: column;
align-items: center;
width: 500px;
margin: 15vh auto;
margin-bottom: -60vh;
border-radius: 15px;
border: none;
box-shadow: 0 0 15px rgb(24, 143, 190);
}
form {
display: flex;
flex-direction: column;
align-items: center;
width: 90%;
}
input {
width: 100%;
margin: 5px 0;
height: 35px;
font-size: 17px;
text-align: center;
outline: none;
border-radius: 15px;
border: none;
background: rgb(235, 228, 228);
}
textarea {
width: 100%;
margin: 5px 0;
font-size: 17px;
text-align: center;
outline: none;
border-radius: 15px;
border: none;
background: rgb(235, 228, 228);
}
input[type=submit]{
margin: 10px auto;
width: 120px;
background: rgb(24, 143, 190);
color: white;
cursor: pointer;
}
input[type=submit]:hover{
background: rgb(19, 41, 238);
}
#media screen and (max-width:600px) {
.form1{
width: 90%;
}
}
h2 {
color: #00ffd5;
font-size: 30px;
}
p4 {
color: #00ffd5;
font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="img/icon.png" />
<link rel="stylesheet" href="styles.css" />
<title>Contact Us</title>
</head>
<body>
<!-- Alert bar -->
<div class="container">
<div class="alert">
<span
class="closebtn"
onclick="this.parentElement.style.display='none';"
>×</span>
<center>
<strong>DEALS NOW ON!</strong> Upto 30% discounts this
christmas
</center>
</div>
<!-- Navigation bar -->
<ul class="topnav">
<li><img src="img/logo.png" /></li>
<li>Home</li>
<li>Products</li>
<li><a class="active" href="contactus.html">Contact Us</a></li>
<li class="right">About Us</li>
</ul>
<!-- Form -->
<div class="form1">
<h2>Contact Us!</h2>
<p4>Typical Replies Within 24hrs!</p4>
<br>
<form action="">
<input type="email" name="email" id="email" placeholder="Enter your email">
<input type="text" name="name" id="name" placeholder=" Enter your name">
<textarea name="message" id="message" cols="30" rows="10" placeholder="Enter your message here"></textarea>
<input type="submit" value="Send">
</form>
</div>
</div>
<!-- Footer -->
<div class="footer__container">
<div class="footer__links">
<div class="footer__link--wrapper">
<div class="footer__link--items">
About Us
</div>
<div class="footer__link--items">
Contact Us
</div>
</div>
<div class="footer__link--wrapper">
<div class="footer__link--items">
Youtube
</div>
<div class="footer__link--items">
TikTok
</div>
</div>
</div>
<section class="social__media">
<div class="social__media--wrap">
<div class="footer__logo">
<a href="index.html">
<img src="img/logo2.png" id="footer__logo" ></a>
</div>
<p class="website__rights">© KIPPLO.CO.UK PROTOTYPE 2022. All rights reserved</p>
<div class="social__icons">
</div>
</div>
</section>
</div>
</body>
</html>
I've adjusted the css to remove the height and margin on the containers:
body {
background-color: black;
}
/* Announcment bar */
.alert {
padding: 20px;
background-color: #2a7a85;
color: white;
}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
body {
margin: 0;
}
/* Navigation bar */
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(248, 248, 248);
}
ul.topnav li {
float: left;
}
ul.topnav li a {
display: block;
color: black;
text-align: center;
font-weight: bold;
padding: 25px 32px;
text-decoration: none;
}
ul.topnav li a:hover:not(.active) {
background-color: rgb(55, 81, 165);
}
ul.topnav li a.active {
background-color: #0cc0d8;
}
ul.topnav li.right {
float: right;
}
#media screen and (max-width: 600px) {
ul.topnav li.right,
ul.topnav li {
float: none;
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.text {
font-size: 11px;
}
}
/* Homepage button */
.glow-on-hover {
width: 220px;
height: 35px;
border: none;
outline: none;
color: rgb(0, 0, 0);
font-weight: bold;
font-size: 20px;
background: #111;
cursor: pointer;
position: relative;
z-index: 0;
border-radius: 10px;
}
.glow-on-hover:before {
content: "";
background: linear-gradient(
45deg,
#ff0000,
#ff7300,
#fffb00,
#48ff00,
#00ffd5,
#002bff,
#7a00ff,
#ff00c8,
#ff0000
);
position: absolute;
top: -2px;
left: -2px;
background-size: 400%;
z-index: -1;
filter: blur(5px);
width: calc(100% + 4px);
height: calc(100% + 4px);
animation: glowing 20s linear infinite;
opacity: 0;
transition: opacity 0.3s ease-in-out;
border-radius: 10px;
}
.glow-on-hover:active {
color: #000;
}
.glow-on-hover:active:after {
background: transparent;
}
.glow-on-hover:hover:before {
opacity: 1;
}
.glow-on-hover:after {
z-index: -1;
content: "";
position: absolute;
width: 100%;
height: 100%;
background: rgb(11, 78, 223);
left: 0;
top: 0;
border-radius: 10px;
}
#keyframes glowing {
0% {
background-position: 0 0;
}
50% {
background-position: 400% 0;
}
100% {
background-position: 0 0;
}
}
/* kipplo heading on homepage */
h1 {
font-size: 10vw;
margin: 0;
padding: 0;
font-family: "Courier New", Courier, monospace;
color: blue;
word-wrap: break-word;
text-align: center;
}
/* for the heading and the button alignment*/
.container {
display: flex;
flex-direction: column;
}
.btn-centering {
flex-grow: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* product cards*/
h3 {
text-align: center;
font-size: 30px;
margin: 0;
padding-top: 10px;
}
a {
text-decoration: none;
}
.gallery {
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: center;
align-items: center;
margin: 50px 0;
}
.content {
width: 24%;
margin: 15px;
box-sizing: border-box;
float: left;
text-align: center;
border-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
padding-top: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: 0.4s;
background-color: whitesmoke;
}
.content:hover {
box-shadow: 0 0 11px rgb(0, 217, 255);
transform: translate(0px, -8px);
transition: 0.6s;
}
.productcard-image {
width: 200px;
height: 200px;
text-align: center;
margin: 0 auto;
display: block;
}
p {
text-align: center;
color: #b2bec3;
padding: 0 8px;
}
h6 {
font-size: 26px;
text-align: center;
color: #222f3e;
margin: 0;
}
.product-card {
list-style-type: none;
display: flex;
justify-content: center;
align-items: center;
padding: 0px;
}
.productcard-list {
padding: 5px;
}
.fa {
color: #ff9f43;
font-size: 26px;
transition: 0.4s;
}
.fa:hover {
transform: scale(1.3);
transition: 0.6s;
}
.productcardbutton {
text-align: center;
font-size: 24px;
color: #fff;
width: 100%;
padding: 15px;
border: 0px;
outline: none;
cursor: pointer;
margin-top: 5px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
.buy-1 {
background-color: #2183a2;
}
.buy-2 {
background-color: #3b3e6e;
}
.buy-3 {
background-color: #0b0b0b;
}
#media (max-width: 1000px) {
.content {
width: 46%;
}
}
#media (max-width: 750px) {
.content {
width: 100%;
}
}
/* Footer */
.footer__container {
background-color: #141414;
padding: 5rem 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#footer__logo {
color: #fff;
display: flex;
align-items: center;
cursor: pointer;
text-decoration: none;
font-size: 2rem;
}
.footer__links {
width: 100%;
max-width: 1000px;
display: flex;
justify-content: center;
}
.footer__link--wrapper {
display: flex;
}
.footer__link--items {
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 16px;
text-align: left;
width: 160px;
box-sizing: border-box;
}
.footer__link--items h2 {
margin-bottom: 16px;
}
.footer__link--items > h2 {
color: #fff;
}
.footer__link--items a {
color: #fff;
text-decoration: none;
margin-bottom: 0.5rem;
}
.footer__link--items a:hover {
color: #e9e9e9;
transition: 0.3s ease-out;
}
/* Social Icons */
.social__icon--link {
color: #fff;
font-size: 24px;
}
.social__media {
max-width: 1000px;
width: 100%;
}
.social__media--wrap {
display: flex;
justify-content: space-between;
align-items: center;
width: 90%;
max-width: 1000px;
margin: 40px auto 0 auto;
}
.website__rights {
color: #fff;
}
#media screen and (max-width: 820px) {
.footer__links {
padding-top: 2rem;
}
#footer__logo {
margin-bottom: 2rem;
}
.website__rights {
padding: 2rem;
}
.footer__link--wrapper {
flex-direction: column;
}
.social__media--wrap {
flex-direction: column;
}
}
#media screen and (max-width: 480px) {
.footer__link--items {
margin: 0;
padding: 10px;
width: 100%;
}
}
/* Text above the form*/
/* Feedback form*/
.form1 {
display: flex;
flex-direction: column;
align-items: center;
width: 500px;
margin: 15vh auto;
border-radius: 15px;
border: none;
box-shadow: 0 0 15px rgb(24, 143, 190);
}
form {
display: flex;
flex-direction: column;
align-items: center;
width: 90%;
}
input {
width: 100%;
margin: 5px 0;
height: 35px;
font-size: 17px;
text-align: center;
outline: none;
border-radius: 15px;
border: none;
background: rgb(235, 228, 228);
}
textarea {
width: 100%;
margin: 5px 0;
font-size: 17px;
text-align: center;
outline: none;
border-radius: 15px;
border: none;
background: rgb(235, 228, 228);
}
input[type="submit"] {
margin: 10px auto;
width: 120px;
background: rgb(24, 143, 190);
color: white;
cursor: pointer;
}
input[type="submit"]:hover {
background: rgb(19, 41, 238);
}
#media screen and (max-width: 600px) {
.form1 {
width: 90%;
}
}
h2 {
color: #00ffd5;
font-size: 30px;
}
p4 {
color: #00ffd5;
font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="img/icon.png" />
<link rel="stylesheet" href="styles.css" />
<title>Contact Us</title>
</head>
<body>
<!-- Alert bar -->
<div class="container">
<div class="alert">
<span
class="closebtn"
onclick="this.parentElement.style.display='none';"
>×</span
>
<center>
<strong>DEALS NOW ON!</strong> Upto 30% discounts this christmas
</center>
</div>
<!-- Navigation bar -->
<ul class="topnav">
<li><img src="img/logo.png" /></li>
<li>Home</li>
<li>Products</li>
<li><a class="active" href="contactus.html">Contact Us</a></li>
<li class="right">About Us</li>
</ul>
<!-- Form -->
<div class="form1">
<h2>Contact Us!</h2>
<p4>Typical Replies Within 24hrs!</p4>
<br />
<form action="">
<input
type="email"
name="email"
id="email"
placeholder="Enter your email"
/>
<input
type="text"
name="name"
id="name"
placeholder=" Enter your name"
/>
<textarea
name="message"
id="message"
cols="30"
rows="10"
placeholder="Enter your message here"
></textarea>
<input type="submit" value="Send" />
</form>
</div>
</div>
<!-- Footer -->
<div class="footer__container">
<div class="footer__links">
<div class="footer__link--wrapper">
<div class="footer__link--items">
About Us
</div>
<div class="footer__link--items">
Contact Us
</div>
</div>
<div class="footer__link--wrapper">
<div class="footer__link--items">
Youtube
</div>
<div class="footer__link--items">
TikTok
</div>
</div>
</div>
<section class="social__media">
<div class="social__media--wrap">
<div class="footer__logo">
<a href="index.html">
<img src="img/logo2.png" id="footer__logo"
/></a>
</div>
<p class="website__rights">
© KIPPLO.CO.UK PROTOTYPE 2022. All rights reserved
</p>
<div class="social__icons"></div>
</div>
</section>
</div>
</body>
</html>

Auto adjusting form using margin

I'm using margins for my form but when I am testing the responsive layout the distance between the navigation bar increases if the screen width is a greater size. Therefore, I have also tried auto height but it still has a big gap between the navigation bar and the form.
I have also tried #media screen.
I had help yesterday with a similar problem to this, but now I'm encountering another one as its not with the footer but with the form itself.
I would kindly like to ask for help, and if you find a solution explain the changes so I can also learn from it! Kindest regards, Caelan : ).
body {
background-color: black;
}
/* Announcment bar */
.alert {
padding: 20px;
background-color: #2a7a85;
color: white;
}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
body {
margin: 0;
}
/* Navigation bar */
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(248, 248, 248);
}
ul.topnav li {
float: left;
}
ul.topnav li a {
display: block;
color: black;
text-align: center;
font-weight: bold;
padding: 25px 32px;
text-decoration: none;
}
ul.topnav li a:hover:not(.active) {
background-color: rgb(55, 81, 165);
}
ul.topnav li a.active {
background-color: #0cc0d8;
}
ul.topnav li.right {
float: right;
}
#media screen and (max-width: 600px) {
ul.topnav li.right,
ul.topnav li {
float: none;
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.text {
font-size: 11px;
}
}
/* Homepage button */
.glow-on-hover {
width: 220px;
height: 35px;
border: none;
outline: none;
color: rgb(0, 0, 0);
font-weight: bold;
font-size: 20px;
background: #111;
cursor: pointer;
position: relative;
z-index: 0;
border-radius: 10px;
}
.glow-on-hover:before {
content: "";
background: linear-gradient(
45deg,
#ff0000,
#ff7300,
#fffb00,
#48ff00,
#00ffd5,
#002bff,
#7a00ff,
#ff00c8,
#ff0000
);
position: absolute;
top: -2px;
left: -2px;
background-size: 400%;
z-index: -1;
filter: blur(5px);
width: calc(100% + 4px);
height: calc(100% + 4px);
animation: glowing 20s linear infinite;
opacity: 0;
transition: opacity 0.3s ease-in-out;
border-radius: 10px;
}
.glow-on-hover:active {
color: #000;
}
.glow-on-hover:active:after {
background: transparent;
}
.glow-on-hover:hover:before {
opacity: 1;
}
.glow-on-hover:after {
z-index: -1;
content: "";
position: absolute;
width: 100%;
height: 100%;
background: rgb(11, 78, 223);
left: 0;
top: 0;
border-radius: 10px;
}
#keyframes glowing {
0% {
background-position: 0 0;
}
50% {
background-position: 400% 0;
}
100% {
background-position: 0 0;
}
}
/* kipplo heading on homepage */
h1 {
font-size: 10vw;
margin: 0;
padding: 0;
font-family: "Courier New", Courier, monospace;
color: blue;
word-wrap: break-word;
text-align: center;
}
/* for the heading and the button alignment*/
.container {
display: flex;
flex-direction: column;
height: 100vh;
}
.btn-centering {
flex-grow: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
/* product cards*/
h3 {
text-align: center;
font-size: 30px;
margin: 0;
padding-top: 10px;
}
a {
text-decoration: none;
}
.gallery {
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: center;
align-items: center;
margin: 50px 0;
}
.content {
width: 24%;
margin: 15px;
box-sizing: border-box;
float: left;
text-align: center;
border-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
padding-top: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: 0.4s;
background-color: whitesmoke;
}
.content:hover {
box-shadow: 0 0 11px rgb(0, 217, 255);
transform: translate(0px, -8px);
transition: 0.6s;
}
.productcard-image {
width: 200px;
height: 200px;
text-align: center;
margin: 0 auto;
display: block;
}
p {
text-align: center;
color: #b2bec3;
padding: 0 8px;
}
h6 {
font-size: 26px;
text-align: center;
color: #222f3e;
margin: 0;
}
.product-card {
list-style-type: none;
display: flex;
justify-content: center;
align-items: center;
padding: 0px;
}
.productcard-list {
padding: 5px;
}
.fa {
color: #ff9f43;
font-size: 26px;
transition: 0.4s;
}
.fa:hover {
transform: scale(1.3);
transition: 0.6s;
}
.productcardbutton {
text-align: center;
font-size: 24px;
color: #fff;
width: 100%;
padding: 15px;
border: 0px;
outline: none;
cursor: pointer;
margin-top: 5px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
.buy-1 {
background-color: #2183a2;
}
.buy-2 {
background-color: #3b3e6e;
}
.buy-3 {
background-color: #0b0b0b;
}
#media (max-width: 1000px) {
.content {
width: 46%;
}
}
#media (max-width: 750px) {
.content {
width: 100%;
}
}
/* Footer */
.footer__container {
background-color: #141414;
padding: 5rem 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#footer__logo {
color: #fff;
display: flex;
align-items: center;
cursor: pointer;
text-decoration: none;
font-size: 2rem;
}
.footer__links {
width: 100%;
max-width: 1000px;
display: flex;
justify-content: center;
}
.footer__link--wrapper {
display: flex;
}
.footer__link--items {
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 16px;
text-align: left;
width: 160px;
box-sizing: border-box;
}
.footer__link--items h2 {
margin-bottom: 16px;
}
.footer__link--items > h2 {
color: #fff;
}
.footer__link--items a {
color: #fff;
text-decoration: none;
margin-bottom: 0.5rem;
}
.footer__link--items a:hover {
color: #e9e9e9;
transition: 0.3s ease-out;
}
/* Social Icons */
.social__icon--link {
color: #fff;
font-size: 24px;
}
.social__media {
max-width: 1000px;
width: 100%;
}
.social__media--wrap {
display: flex;
justify-content: space-between;
align-items: center;
width: 90%;
max-width: 1000px;
margin: 40px auto 0 auto;
}
.website__rights {
color: #fff;
}
#media screen and (max-width: 820px) {
.footer__links {
padding-top: 2rem;
}
#footer__logo {
margin-bottom: 2rem;
}
.website__rights {
padding: 2rem;
}
.footer__link--wrapper {
flex-direction: column;
}
.social__media--wrap {
flex-direction: column;
}
}
#media screen and (max-width: 480px) {
.footer__link--items {
margin: 0;
padding: 10px;
width: 100%;
}
}
/* Text above the form*/
/* Feedback form*/
.form1 {
display: flex;
flex-direction: column;
align-items: center;
width: 500px;
margin: 15vh auto;
margin-top: -200px;
height: auto;
border-radius: 15px;
border: none;
box-shadow: 0 0 15px rgb(24, 143, 190);
}
form {
display: flex;
flex-direction: column;
align-items: center;
width: 90%;
}
input {
width: 100%;
margin: 5px 0;
height: 35px;
font-size: 17px;
text-align: center;
outline: none;
border-radius: 15px;
border: none;
background: rgb(235, 228, 228);
}
textarea {
width: 100%;
margin: 5px 0;
font-size: 17px;
text-align: center;
outline: none;
border-radius: 15px;
border: none;
background: rgb(235, 228, 228);
}
input[type="submit"] {
margin: 10px auto;
width: 120px;
background: rgb(24, 143, 190);
color: white;
cursor: pointer;
}
input[type="submit"]:hover {
background: rgb(19, 41, 238);
}
#media screen and (max-width: 600px) {
.form1 {
width: 90%;
margin-top:-250px;
height: auto;
}
}
h2 {
color: #00ffd5;
font-size: 30px;
}
p4 {
color: #00ffd5;
font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="img/icon.png" />
<link rel="stylesheet" href="styles.css" />
<title>Contact Us</title>
</head>
<body>
<!-- Alert bar -->
<div class="container">
<div class="alert">
<span
class="closebtn"
onclick="this.parentElement.style.display='none';"
>×</span
>
<center>
<strong>DEALS NOW ON!</strong> Upto 30% discounts this christmas
</center>
</div>
<!-- Navigation bar -->
<ul class="topnav">
<li><img src="img/logo.png" /></li>
<li>Home</li>
<li>Products</li>
<li><a class="active" href="contactus.html">Contact Us</a></li>
<li class="right">About Us</li>
</ul>
</div>
<!-- Form -->
<div class="form1">
<h2>Contact Us!</h2>
<p4>Typical Replies Within 24hrs!</p4>
<br />
<form action="">
<input
type="email"
name="email"
id="email"
placeholder="Enter your email"
/>
<input
type="text"
name="name"
id="name"
placeholder=" Enter your name"
/>
<textarea
name="message"
id="message"
cols="30"
rows="10"
placeholder="Enter your message here"
></textarea>
<input type="submit" value="Send" />
</form>
</div>
</div>
<!-- Footer -->
<div class="footer__container">
<div class="footer__links">
<div class="footer__link--wrapper">
<div class="footer__link--items">
About Us
</div>
<div class="footer__link--items">
Contact Us
</div>
</div>
<div class="footer__link--wrapper">
<div class="footer__link--items">
Youtube
</div>
<div class="footer__link--items">
TikTok
</div>
</div>
</div>
<section class="social__media">
<div class="social__media--wrap">
<div class="footer__logo">
<a href="index.html">
<img src="img/logo2.png" id="footer__logo"
/></a>
</div>
<p class="website__rights">
© KIPPLO.CO.UK PROTOTYPE 2022. All rights reserved
</p>
<div class="social__icons"></div>
</div>
</[![section][1]][1]>
</div>
</body>
</html>
I analyzed your code. You have just to remove the height: 100vh from your .container.
The next step is to remove the margin-top: -250px from your .form1. then it should look good.
Bonus Tip: the unit vh stands for viewport-height (browser height). so 100vh is 100% of the viewport height.

Is there a way to use <li> instead of a <button> element?

Is there a way to use <li> instead of a <button> element and still achieve the same result as using a button?
I have a navbar and in the middle of the navbar, there is a button because I have a drop-down menu (once you click the button the dropdown shows up) I want to change the button into a list item in order to get the exact same look(CSS) as the rest of the navbar.
My Code:
/*===== GOOGLE FONTS =====*/
#import url("https://fonts.googleapis.com/css2?family=Poppins:wght#400;600;700&display=swap");
/*===== VARIABLES CSS =====*/
:root {
--header-height: 3rem;
--font-semi: 600;
}
/*===== Colores =====*/
:root {
--first-color: #FF0000;
--second-color: #0E2431;
}
/*===== Fuente y tipografia =====*/
:root {
--body-font: 'Poppins', sans-serif;
--big-font-size: 2rem;
--h2-font-size: 1.25rem;
--normal-font-size: 0.938rem;
}
#media screen and (min-width: 768px) {
:root {
--big-font-size: 3.5rem;
--h2-font-size: 2rem;
--normal-font-size: 1rem;
}
}
/*===== Margenes =====*/
:root {
--mb-1: 0.5rem;
--mb-2: 1rem;
--mb-3: 1.5rem;
--mb-4: 2rem;
--mb-5: 2.5rem;
--mb-6: 3rem;
}
/*===== z index =====*/
:root {
--z-back: -10;
--z-normal: 1;
--z-tooltip: 10;
--z-fixed: 100;
}
/*===== BASE =====*/
*,
::before,
::after {
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
margin: var(--header-height) 0 0 0;
font-family: var(--body-font);
font-size: var(--normal-font-size);
color: var(--second-color);
}
h1,
h2,
p {
margin: 0;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
a {
text-decoration: none;
}
img {
max-width: 100%;
height: auto;
display: block;
}
/*===== CLASS CSS ===== */
.section-title {
position: relative;
font-size: var(--h2-font-size);
color: var(--first-color);
margin-top: var(--mb-2);
margin-bottom: var(--mb-4);
text-align: center;
}
.section-title::after {
position: absolute;
content: "";
width: 64px;
height: 0.18rem;
left: 0;
right: 0;
margin: auto;
top: 2rem;
background-color: var(--first-color);
}
.section {
padding-top: 3rem;
padding-bottom: 2rem;
}
/*===== LAYOUT =====*/
.bd-grid {
max-width: 1024px;
display: grid;
grid-template-columns: 100%;
grid-column-gap: 2rem;
width: calc(100% - 2rem);
margin-left: var(--mb-2);
margin-right: var(--mb-2);
}
.l-header {
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: var(--z-fixed);
background-color: #fff;
box-shadow: 0 1px 4px rgba(146, 161, 176, .15);
}
/*===== NAV =====*/
.nav {
height: var(--header-height);
display: flex;
justify-content: space-between;
align-items: center;
font-weight: var(--font-semi);
}
#media screen and (max-width: 768px) {
.nav__menu {
position: fixed;
top: var(--header-height);
right: -100%;
width: 80%;
height: 100%;
padding: 2rem;
background-color: var(--second-color);
transition: .5s;
}
}
.nav__item {
margin-bottom: var(--mb-4);
}
.nav__link {
position: relative;
color: #fff;
}
.nav__link:hover {
position: relative;
}
.nav__link:hover::after {
position: absolute;
content: "";
width: 100%;
height: 0.18rem;
left: 0;
top: 2rem;
background-color: var(--first-color);
}
.nav__logo {
color: var(--second-color);
}
.nav__toggle {
color: var(--second-color);
font-size: 1.5rem;
cursor: pointer;
}
/*Active menu*/
.active::after {
position: absolute;
content: "";
width: 100%;
height: 0.18rem;
left: 0;
top: 2rem;
background-color: var(--first-color);
}
/*=== Show menu ===*/
.show {
right: 0;
}
/*===== HOME =====*/
.home {
height: calc(100vh - 3rem);
row-gap: 1rem;
}
.home__data {
align-self: center;
}
.home__title {
font-size: var(--big-font-size);
margin-bottom: var(--mb-5);
}
.home__title-color {
color: var(--first-color);
}
.home__social {
display: flex;
flex-direction: column;
}
.home__social-icon {
width: max-content;
margin-bottom: var(--mb-2);
font-size: 1.5rem;
color: var(--second-color);
}
.home__social-icon:hover {
color: var(--first-color);
}
.home__img {
position: absolute;
right: 0;
bottom: 0;
width: 295px;
}
/*BUTTONS*/
.button {
display: inline-block;
background-color: var(--first-color);
color: #fff;
padding: .75rem 2.5rem;
font-weight: var(--font-semi);
border-radius: .5rem;
}
.button:hover {
box-shadow: 0 10px 36px rgba(0, 0, 0, .15);
}
/* ===== ABOUT =====*/
.about__container {
row-gap: 2rem;
text-align: center;
}
.about__subtitle {
margin-bottom: var(--mb-2);
}
.about__img {
justify-self: center;
}
.about__img img {
width: 200px;
border-radius: .5rem;
}
/* ===== SKILLS =====*/
.skills__container {
row-gap: 2rem;
text-align: center;
}
.skills__subtitle {
margin-bottom: var(--mb-2);
}
.skills__text {
margin-bottom: var(--mb-4);
}
.skills__data {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
font-weight: var(--font-semi);
padding: .5rem 1rem;
margin-bottom: var(--mb-4);
border-radius: .5rem;
box-shadow: 0 4px 25px rgba(14, 36, 49, .15);
}
.skills__icon {
font-size: 2rem;
margin-right: var(--mb-2);
color: var(--first-color);
}
.skills__names {
display: flex;
align-items: center;
}
.skills__bar {
position: absolute;
left: 0;
bottom: 0;
background-color: var(--first-color);
height: .25rem;
border-radius: .5rem;
z-index: var(--z-back);
}
.skills__html {
width: 95%;
}
.skills__css {
width: 85%;
}
.skills__js {
width: 65%;
}
.skills__ux {
width: 85%;
}
.skills__img {
border-radius: .5rem;
}
/* ===== WORK =====*/
.work__container {
row-gap: 2rem;
}
.work__img {
box-shadow: 0 4px 25px rgba(14, 36, 49, .15);
border-radius: .5rem;
overflow: hidden;
}
.work__img img {
transition: 1s;
cursor: pointer;
}
.work__img img:hover {
transform: scale(1.1);
}
/* ===== CONTACT =====*/
.contact__input {
width: 100%;
font-size: var(--normal-font-size);
font-weight: var(--font-semi);
padding: 1rem;
border-radius: .5rem;
border: 1.5px solid var(--second-color);
outline: none;
margin-bottom: var(--mb-4);
}
.contact__button {
display: block;
border: none;
outline: none;
font-size: var(--normal-font-size);
cursor: pointer;
margin-left: auto;
}
/* ===== FOOTER =====*/
.footer {
background-color: var(--second-color);
color: #fff;
text-align: center;
font-weight: var(--font-semi);
padding: 2rem 0;
}
.footer__title {
font-size: 2rem;
margin-bottom: var(--mb-4);
}
.footer__social {
margin-bottom: var(--mb-4);
}
.footer__icon {
font-size: 1.5rem;
color: #fff;
margin: 0 var(--mb-2)
}
/* ===== MEDIA QUERIES=====*/
#media screen and (min-width: 768px) {
body {
margin: 0;
}
.section {
padding-top: 4rem;
padding-bottom: 3rem;
}
.section-title {
margin-bottom: var(--mb-6);
}
.section-title::after {
width: 80px;
top: 3rem;
}
.nav {
height: calc(var(--header-height) + 1rem);
}
.nav__list {
display: flex;
padding-top: 0;
}
.nav__item,
.products button {
margin-left: var(--mb-6);
margin-bottom: 0;
}
.nav__toggle {
display: none;
}
.nav__link {
color: var(--second-color);
}
.home {
height: 100vh;
}
.home__data {
align-self: flex-end;
}
.home__social {
padding-top: 0;
padding-bottom: 2.5rem;
flex-direction: row;
align-self: flex-end;
}
.home__social-icon {
margin-bottom: 0;
margin-right: var(--mb-4);
}
.home__img {
width: 457px;
bottom: 30%;
}
.about__container,
.skills__container {
grid-template-columns: repeat(2, 1fr);
align-items: center;
text-align: initial;
}
.about__img img {
width: 300px;
}
.work__container {
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
column-gap: 2rem;
}
.contact__form {
width: 360px;
}
.contact__container {
justify-items: center;
}
}
#media screen and (min-width: 1024px) {
.bd-grid {
margin-left: auto;
margin-right: auto;
}
.home__img {
right: 10%;
}
}
.dropdown {
height: 10vh;
width: 60%;
margin: auto;
display: flex;
justify-content: space-around;
align-items: center;
}
.products {
position: relative;
}
.products ul {
margin-top: 10px;
position: absolute;
display: flex;
justify-content: space-around;
flex-direction: column;
align-items: center;
width: 200px;
height: 350px;
background: white;
left: 0px;
list-style: none;
border-radius: 5px;
opacity: 0;
pointer-events: none;
transform: translateY(-10px);
transition: all 0.4s ease;
}
.products li {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.products li:hover {
background-color: rgb(255, 255, 255);
}
.products a {
color: black;
text-decoration: none;
}
.products button:focus+ul {
opacity: 1;
pointer-events: all;
transform: translateY(0px);
}
<header class="l-header">
<nav class="nav bd-grid">
<div>
My Company Name
</div>
<div class="nav__menu" id="nav-menu">
<ul class="nav__list" id="nav">
<li class="nav__item">Home</li>
<li class="nav__item">About</li>
<div class="products">
<button class="nav__button">Products</button>
<ul>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
</ul>
</div>
<li class="nav__item">Distributors</li>
<li class="nav__item">Contact</li>
<li class="nav__item">EXAMPLE</li>
<div class="nav__toggle" id="nav-toggle">
<i class='bx bx-menu'></i>
</div>
</nav>
</header>
Here, you will have to learn JS, its best for manipulating DOM. And all you need is here on SO already answered.
With CSS i hide all but first li item
Then in JS i save ul element in nav variable
let nav = document.querySelector("#nav-menu .products ul")
Add event listener to first li item
nav.querySelector("li:first-of-type").addEventListener("click", function() {
If pressed show the rest:
nav.querySelectorAll("li").forEach(li => li.style.display="block")
let nav = document.querySelector("#nav-menu .products ul")
nav.querySelector("li:first-of-type").addEventListener("click", function() {
nav.querySelectorAll("li").forEach(li => li.style.display="block")
});
#nav-menu .products ul li:not(li:first-of-type){
display:none}
<header class="l-header">
<nav class="nav bd-grid">
<div>
My Company Name
</div>
<div class="nav__menu" id="nav-menu">
<ul class="nav__list" id="nav">
<li class="nav__item">Home</li>
<li class="nav__item">About</li>
<div class="products">
<ul>
<li><a class="nav__link" href="#">Products <--- click</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
<li><a class="nav__link" href="#">EXAMPLE</a></li>
</ul>
</div>
<li class="nav__item">Distributors</li>
<li class="nav__item">Contact</li>
<li class="nav__item">EXAMPLE</li>
</div>
<div class="nav__toggle" id="nav-toggle">
<i class='bx bx-menu'></i>
</div>
</nav>
</header>