navbar is not appearing on mobile phones view - html

my problem is when i press on the hamburger menu the whole menu does not appear (in mobile view) - even though i'm sure about the code and it working properly, the only problem in mobile view i can't diplay all the main menu ( work - blog - contact ) so when i hover on the icon i don't get anything.
nav-bar {
font-size: 18px;
padding-bottom: 10px;
}
.main-menu {
list-style-type: none;
}
.main-menu li {
text-align: center;
margin: 15px auto;
}
.main-menu a {
text-decoration: none;
color: black;
}
.main-menu a:hover {
text-decoration: overline;
}
.main-menu li i {
padding-right: 10px;
}
.logo {
margin-top: 10px;
margin-left: 20px;
width: 200px;
}
.logo img {
width: 40px;
border-radius: 20px;
margin-top: 20px;
margin-left: 30px;
margin-bottom: 30px;
}
.menu-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: black;
font-size: 24px;
}
.active {
display: block;
}
.main-menu {
display: none;
}
#media screen and (min-width: 60rem) {
/*Desktop view*/
.nav-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 0;
min-height: 70px;
}
.main-menu {
display: flex;
flex-wrap: wrap;
margin-right: 30px;
}
.main-menu li {
margin: 0px 0px 5px 0px;
}
.main-menu a {
margin-left: 40px;
}
/* Hide the menu toogle icon when the full menu is visible */
.menu-toggle {
display: none;
}
}
<nav class="nav-bar">
<!-- The Toggle Button is used to hide and show the menu for a Mobile Layout -->
<span class="menu-toggle">
<i class="fas fa-bars"></i>
</span>
<a href="#" class="logo">
<img src="img/logo.png" alt="Logo">
</a>
<ul class="main-menu">
<li>
<i class="fas fa-home"></i>Works
</li>
<li>
<i class="fas fa-university"></i>Blogs
</li>
<li>
<i class="fas fa-headset"></i>Contact
</li>
</ul>
</nav>

Your main-menu CSS is set to display none for mobile.
.main-menu {
display: none;
}
You need to tell it what to do like you did with desktop:
.main-menu {
display: flex;
flex-wrap: wrap;
margin-right: 30px;
}

The main issue was that the menu wasn't being hidden / shown. I corrected that and added a css transition. You can use js instead of the input to keep track of the menu state on mobile.
.nav-bar {
font-size: 18px;
padding-bottom: 10px;
overflow: hidden;
}
.main-menu {
list-style-type: none;
}
.main-menu li {
text-align: center;
margin: 15px auto;
}
.main-menu a {
text-decoration: none;
color: black;
}
.main-menu a:hover {
text-decoration: overline;
}
.main-menu li i {
padding-right: 10px;
}
.logo {
margin-top: 10px;
margin-left: 20px;
width: 200px;
}
.logo img {
width: 40px;
border-radius: 20px;
margin-top: 20px;
margin-left: 30px;
margin-bottom: 30px;
}
.menu-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: black;
font-size: 24px;
width: 32px;
height: 32px;
}
#menu-toggle-checkbox {
display: none;
}
.active {
display: block;
}
.main-menu {
transform: translate(100%);
transition: transform 1s;
}
#media screen and (min-width: 60rem) {
/*Desktop view*/
.nav-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 0;
min-height: 70px;
}
.main-menu {
display: flex;
flex-wrap: wrap;
margin-right: 30px;
transform: translate(0%);
}
.main-menu li {
margin: 0px 0px 5px 0px;
}
.main-menu a {
margin-left: 40px;
}
/* Hide the menu toogle icon when the full menu is visible */
.menu-toggle {
display: none;
}
}
#media screen and (max-width: 60rem) {
.menu-toggle {
display: block;
}
#menu-toggle-checkbox:checked + .logo + .main-menu {
transform: translateX(0)
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="nav-bar">
<!-- The Toggle Button is used to hide and show the menu for a Mobile Layout -->
<label class="menu-toggle" for="menu-toggle-checkbox">
<i class="fa fa-bars"></i>
</label>
<input type="checkbox" id="menu-toggle-checkbox"/>
<a href="#" class="logo">
<img src="img/logo.png" alt="Logo">
</a>
<ul class="main-menu">
<li>
<i class="fas fa-home"></i>Works
</li>
<li>
<i class="fas fa-university"></i>Blogs
</li>
<li>
<i class="fas fa-headset"></i>Contact
</li>
</ul>
</nav>

Related

Fixed position html css sidebar scrolls in mobile view when not supposed to

I am currently building out my portfolio, and while working on the sidebar and testing for mobile responsivness, i ran into a small problem.
i have a div that acts as my sidebar, it has a position fixed, with a top and left 0. and in desktop view, it stays on scroll and works as i would expect. however through the inspect tab, and mobile view, the sidebar scrolls with the page. Code is attached below, in a perfect world i would be able to keep the sidebar where it is supposed to be in the mobile view. and this is specific to the mobile view, if you just shrink the main window to the media query width, it works as expected. Thanks!!
EDIT:
What iwant it to look like: https://youtu.be/w3AT3WHHL4o
what it looks like: https://youtu.be/kbfS8vBKAlU
<div class="side-nav">
<a href="#home" class="logo">
<img class="logo-img" src="Images/Logo.png">
<img class="icon-img" src="Images/Icon.png">
</a>
<ul class="nav-links">
<li><i class="fa-solid fa-user scrollLink"></i><p>About</p></li>
<li><i class="fa-solid fa-folder scrollLink"></i><p>Projects</p></li>
<li><i class="fa-solid fa-file scrollLink"></i><p>Resume</p></li>
<div class="active"></div>
</ul>
</div>
<style>
.side-nav {
width: 250px;
height: 100vh;
background: #9E9E9E;
position: fixed;
top: 0;
left: 0;
padding: 20px 30px;
}
.logo {
display: block;
margin-bottom: 130px;
}
.logo-img {
display: block;
width: 190px;
}
.icon-img {
display: none;
}
.nav-links {
list-style: none;
position: relative;
}
.nav-links li {
padding: 10px 0;
}
.nav-links li a {
color: white;
text-decoration: none;
padding: 10px 14px;
display: flex;
align-items: center;
}
.nav-links li a i {
font-size: 22px;
margin-right: 20px;
}
.active {
background: white;
width: 100%;
height: 47px;
position: absolute;
left: 0;
top: 4%;
z-index: -1;
border-radius: 6px;
box-shadow: 0 5px 10px rgba(255, 255, 255, 0.4);
display: none;
transition: top 0.5s;
}
.nav-links li:hover a {
color: #9E9E9E;
transition: 0.3s;
}
.nav-links li:hover ~ .active {
display: block;
}
.nav-links li:nth-child(1):hover ~ .active{
top: 4%;
}
.nav-links li:nth-child(2):hover ~ .active{
top: 35.9%;
}
.nav-links li:nth-child(3):hover ~ .active{
top: 69.2%;
}
#media only screen and (max-width: 600px){
.side-nav {
width: 110px;
}
.nav-links li a p {
display: none;
}
.nav-links li a i {
margin-right: 0;
}
.nav-links li a {
justify-content: center;
}
.logo-img {
display: none;
}
.icon-img {
display: block;
}
}
</style>
i have commented the things i added. i am sorry i would not be able to explain because you setup is very messy & need to refactored.
.side-nav {
width: 250px;
height: 100vh;
background: #9E9E9E;
position: fixed;
top: 0;
left: 0;
padding: 20px 30px;
}
.logo {
display: block;
margin-bottom: 130px;
}
.logo-img {
display: block;
width: 190px;
}
.icon-img {
display: none;
}
.nav-links {
list-style: none;
position: relative;
}
.nav-links li {
padding: 10px 0;
}
.nav-links li a {
color: white;
text-decoration: none;
padding: 10px 14px;
display: flex;
align-items: center;
}
.nav-links li a i {
font-size: 22px;
margin-right: 20px;
}
.active {
background: white;
width: 100%;
height: 47px;
position: absolute;
left: 0;
top: 4%;
z-index: -1;
border-radius: 6px;
box-shadow: 0 5px 10px rgba(255, 255, 255, 0.4);
display: none;
transition: top 0.5s;
}
.nav-links li:hover a {
color: #9E9E9E;
transition: 0.3s;
}
.nav-links li:hover~.active {
display: block;
}
.nav-links li:nth-child(1):hover~.active {
top: 4%;
}
.nav-links li:nth-child(2):hover~.active {
top: 35.9%;
}
.nav-links li:nth-child(3):hover~.active {
top: 69.2%;
}
#media only screen and (max-width: 600px) {
.side-nav {
width: 100px;
height: 70vh;
padding: 2px 3px; /*i added*/
display: flex; /*i added*/
flex-direction: column; /*i added*/
align-items: space-between; /*i added*/
}
.nav-links li a i {
font-size: 12px; /*i added*/
margin-right: 0px; /*i added*/
}
.logo {
display: block;
margin-bottom: 30px; /*i added*/
}
.nav-links li a p {
display: none;
}
.nav-links li a i {
margin-right: 0;
}
.nav-links li a {
justify-content: flex-start; /*i added*/
}
.logo-img {
display: none;
}
.icon-img {
display: block;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" rel="stylesheet" />
<div class="side-nav">
<a href="#home" class="logo">
<img class="logo-img" src="Images/Logo.png">
<img class="icon-img" src="Images/Icon.png">
</a>
<ul class="nav-links">
<li><i class="fa-solid fa-user scrollLink"></i><p>About</p></li>
<li><i class="fa-solid fa-folder scrollLink"></i><p>Projects</p></li>
<li><i class="fa-solid fa-file scrollLink"></i><p>Resume</p></li>
<div class="active"></div>
</ul>
</div>

Hamburger icon not showing on mobile

I have a navbar on my Django application. The code for it is below.
.nav-header {
height: 75px;
width: 100%;
float: left;
background: #2e2e2e;
padding: 0 20px;
color: #fff;
margin-bottom: 25px;
border-bottom: 2px solid black;
}
.brand-logo {
max-width: 75px;
float: left;
padding: 14px 0px;
}
.brand-logo img {
max-width: 100%;
}
.navigation {
margin: 0px;
float: right;
}
.navigation li {
list-style: none;
float: left;
}
.navigation li a {
color: #fff;
padding: 28px 15px;
text-transform: uppercase;
text-align: center;
display: block;
text-decoration: none;
}
.navigation li a i {
width: 100%;
font-size: 20px;
margin-bottom: 7px;
}
.show-menu-btn,
.hide-menu-btn {
transition: 0.4s;
font-size: 30px;
cursor: pointer;
display: none;
z-index: 2;
}
.show-menu-btn {
margin: 0px;
margin-top: 15px;
float: right;
}
.show-menu-btn i {
line-height: 100px;
}
.navigation a:hover,
.show-menu-btn:hover,
.hide-menu-btn:hover {
color: #00ff0a;
}
#toggle-btn {
position: absolute;
visibility: hidden;
z-index: -1111;
}
#media screen and (max-width: 767px) {
.show-menu-btn,
.hide-menu-btn {
display: block;
}
.navigation {
position: fixed;
width: 100%;
height: 100vh;
background: #2e2e2e;
top: -100%;
left: 0;
padding: 50px 0px;
transition: 1s;
z-index: 1;
}
.navigation li {
width: 100%;
}
.navigation li a {
padding: 15px 15px;
text-align: left;
}
.navigation li a i {
width: auto;
font-size: 20px;
}
.hide-menu-btn {
position: absolute;
top: 15px;
right: 20px;
}
#toggle-btn:checked ~ nav .navigation {
top: 0px;
}
}
<div class="container">
<input type="checkbox" id="toggle-btn">
<label for="toggle-btn" class="show-menu-btn"><i class="fas fa-bars"></i></label>
<nav>
<ul class="navigation">
<li><i class="fas fa-house-damage"></i> Home</li>
{% if request.user.is_authenticated %}
<li><i class="fas fa-sign-out-alt"></i> Sign Out</li>
{% else %}
<li><i class="fas fa-sign-in-alt"></i> Sign In</li>
<li><i class="fas fa-user-plus"></i> Sign Up</li>
{% endif %}
<label for="toggle-btn" class="hide-menu-btn"><i class="fas fa-times"></i></label>
</ul>
</nav>
</div>
When I test it locally in google chrome on my PC using the device toolbar, it works completely fine. When I deploy it to my Heroku server, the hamburger icon does not show.
The label is there it just is not visible. When I try to randomly tap the screen in the area where it is supposed to be, it works but still does not show.

Trying to create toggle for icon in NavBar using a checkbox

I am trying to use a checkbox to make my font awesome icon trigger the menu icon to open and close the menu (which is how I want it to be design wise) when the screen is in mobile view.
Thanks in advance for any help.
/*** General ***/
* {
font-family: 'Noto Serif SC', serif;
margin: 0;
padding: 0;
}
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 400px;
height: auto;
}
.contents1 {
margin-top: 5vh;
margin-bottom: 10vh;
}
a {
text-decoration: none;
color: black;
margin: none;
padding: none;
}
/*** Header ***/
.header {
margin-top: 20px;
margin-bottom: 20px;
}
.logo {
text-align: center;
font-size: 30px;
}
/*** Navigation ***/
.fa-bars {
display: none;
}
.nav-links {
width: 100%;
float: left;
position: sticky;
align-items: center;
justify-content: center;
padding: 0;
background-color: #f7f7f7;
border-bottom: 1px solid rgb(228, 224, 224);
display: flex;
}
.nav-links li {
list-style: none;
text-align: center;
font-size: 18px;
float: left;
padding: 14px 16px;
}
.nav-links li a {
text-decoration: none;
text-align: center;
float: left;
}
/*** Footer ***/
.footer {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
}
.footer2 {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
}
/*** Media Queries ***/
#media only screen and (max-width: 800px) {
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 375px;
height: auto;
}
}
#media only screen and (max-width: 700px) {
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 350px;
height: auto;
}
}
#media only screen and (max-width: 600px) {
.fa-bars {
font-size: 20px;
display: block;
float: right;
margin-top: 10px;
margin-right: 40px;
cursor: pointer;
}
.logo {
text-align: left;
font-size: 25px;
}
.nav-toggle {
display: none;
}
.nav-links,
ul {
position: fixed;
width: 100%;
height: 100vh;
text-align: center;
background-color: #f7f7f7;
border-bottom: 1px solid rgb(107, 76, 76);
top: 80px;
left: 0;
flex-direction: column;
display: none;
}
.nav-toggle:checked+.nav-links,
ul {
display: flex;
}
.nav-links li {
display: block;
}
.contents1 {
margin-top: 5vh;
}
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght#200&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<div class="header">
<div>
<div class="logo">
<h4>The Blue Lion <i class="fas fa-bars" id="nav-toggle"></i></h4>
<input type="checkbox" id="nav-toggle" class="nav-toggle">
</div>
</div>
<label for="nav-toggle" class="nav-toggle-label">
<span></span>
</label>
</div>
<div class="navbar">
<div class="nav-links" id="myTopnav">
<ul>
<li a href="#">Food</li>
<li a href="#">Drink</li>
<li a href="#">Covid-19</li>
<li a href="#">News</li>
<li a href="#">Join the Team</li>
</ul>
</div>
</div>
<div class="contents1">
<img src="https://mcdn.wallpapersafari.com/medium/84/3/pQuUz4.jpg" class="bluepic" alt="Blue">
</div>
<div class="footer">
<div class="info">
Leave us a review:
<i class="fab fa-tripadvisor"></i>
</div>
<div class="socialiconsf">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
<div class="footer2">
<p>
© The Blue Lion 2021
</p>
</div>
Do this:
* {
font-family: 'Noto Serif SC', serif;
margin: 0;
padding: 0;
}
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 400px;
height: auto;
}
.contents1 {
margin-top: 5vh;
margin-bottom: 10vh;
}
a {
text-decoration: none;
color: black;
margin: none;
padding: none;
}
/*** Header ***/
.header {
margin-top: 20px;
margin-bottom: 20px;
}
.logo {
text-align: center;
font-size: 30px;
}
/*** Navigation ***/
.fa-bars {
display: none;
}
.nav-links {
width: 100%;
float: left;
position: sticky;
align-items: center;
justify-content: center;
padding: 0;
background-color: #f7f7f7;
border-bottom: 1px solid rgb(228, 224, 224);
display: flex;
}
.nav-links li {
list-style: none;
text-align: center;
font-size: 18px;
float: left;
padding: 14px 16px;
}
.nav-links li a {
text-decoration: none;
text-align: center;
float: left;
}
/*** Footer ***/
.footer {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
}
.footer2 {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
}
/*** Media Queries ***/
#media only screen and (max-width: 800px) {
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 375px;
height: auto;
}
}
#media only screen and (max-width: 700px) {
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 350px;
height: auto;
}
}
#media only screen and (max-width: 600px) {
.fa-bars {
font-size: 20px;
display: block;
float: right;
margin-top: 10px;
margin-right: 40px;
cursor: pointer;
}
.logo {
text-align: left;
font-size: 25px;
}
.nav-toggle {
display: none;
}
.nav-links,
ul {
width: 100%;
height: 100vh;
text-align: center;
background-color: #f7f7f7;
border-bottom: 1px solid rgb(107, 76, 76);
top: 80px;
left: 0;
flex-direction: column;
display: none;
}
.nav-toggle:checked+.nav-links,
ul {
display: flex;
}
.nav-links li {
display: block;
}
.contents1 {
margin-top: 5vh;
}
}
#media (max-width:600px){
.hamburger-menu{
position: relative;
}
.checkbox:checked~ .nav-links{
display: block;
}
}
<div class="header">
<div>
<div class="logo">
<h4>The Blue Lion
</div>
</h4>
</div>
<label for="nav-toggle" class="nav-toggle-label">
<span></span>
</label>
</div>
</div>
<div class="navbar">
<input type="checkbox" id="check" class="checkbox" hidden>
<label for="check" class="fas fa-bars"></label>
<div class="nav-links" id="myTopnav">
<ul>
<li a href="#">Food</li>
<li a href="#">Drink</li>
<li a href="#">Covid-19</li>
<li a href="#">News</li>
<li a href="#">Join the Team</li>
</ul>
</div>
</div>
<div class="contents1">
<img src="bluepic1.jpg" class="bluepic" alt="Blue">
</div>
<div class="footer">
<div class="info">
Leave us a review:
<i class="fab fa-tripadvisor"></i>
</div>
<div class="socialiconsf">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
<div class="footer2">
<p>
© The Blue Lion 2021
</p>
</div>
CSS modification:
The font-awesome library overrides your CSS. That is why your menu-icon (.fa-bars) wouldn't hide when not in mobile mode.
I made following corrections to your CSS:
Changing .fa-bars to .fas.fa-bars
Adding !important in mobile mode
(to show always when media break-point (... and (max-width: 600px))
/*** Navigation ***/
.fas.fa-bars {
display: none;
}
#media only screen and (max-width: 600px) {
.fas.fa-bars {
font-size: 20px;
display: block !important;
float: right;
margin-top: 10px;
margin-right: 40px;
cursor: pointer;
}
}
Click event handler on checkBox:
Also, if you want functionality to your checkbox, then you would have to add an event-handler in JS and add the onClick=function() in your HTML (and correct the issue of the multiple assigned id as mentioned in comments: I replaced id="nav-toggle" with id="nav-toggle-bars" for the <i class="fas fa-bars" element).
Following complete code for you to Run code snippet and comment if this is your desired outcome (please advise).
Expand to "full-page" and change your browser width to see effect
below media break-point (... and (max-width: 600px))
const menuToggle = document.getElementById("nav-toggle-bars");
let menuCheckBox;
function showHideNavToggle(event) {
menuCheckBox = event.target;
if (menuCheckBox.checked) {
menuToggle.style.display = "block";
} else {
menuToggle.style.display = "none";
}
}
/*** General ***/
* {
font-family: 'Noto Serif SC', serif;
margin: 0;
padding: 0;
}
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 400px;
height: auto;
}
.contents1 {
margin-top: 5vh;
margin-bottom: 10vh;
}
a {
text-decoration: none;
color: black;
margin: none;
padding: none;
}
/*** Header ***/
.header {
margin-top: 20px;
margin-bottom: 20px;
}
.logo {
text-align: center;
font-size: 30px;
}
/*** Navigation ***/
.fas.fa-bars {
display: none;
}
.nav-links {
width: 100%;
float: left;
position: sticky;
align-items: center;
justify-content: center;
padding: 0;
background-color: #f7f7f7;
border-bottom: 1px solid rgb(228, 224, 224);
display: flex;
}
.nav-links li {
list-style: none;
text-align: center;
font-size: 18px;
float: left;
padding: 14px 16px;
}
.nav-links li a {
text-decoration: none;
text-align: center;
float: left;
}
/*** Footer ***/
.footer {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
}
.footer2 {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
text-align: center;
}
/*** Media Queries ***/
#media only screen and (max-width: 800px) {
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 375px;
height: auto;
}
}
#media only screen and (max-width: 700px) {
.bluepic {
padding-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 350px;
height: auto;
}
}
#media only screen and (max-width: 600px) {
.fas.fa-bars {
font-size: 20px;
display: block !important;
float: right;
margin-top: 10px;
margin-right: 40px;
cursor: pointer;
}
.logo {
text-align: left;
font-size: 25px;
}
.nav-toggle {
display: none;
}
.nav-links,
ul {
position: fixed;
width: 100%;
height: 100vh;
text-align: center;
background-color: #f7f7f7;
border-bottom: 1px solid rgb(107, 76, 76);
top: 80px;
left: 0;
flex-direction: column;
display: none;
}
.nav-toggle:checked+.nav-links,
ul {
display: flex;
}
.nav-links li {
display: block;
}
.contents1 {
margin-top: 5vh;
}
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght#200&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<div class="header">
<div>
<div class="logo">
<h4>The Blue Lion <i class="fas fa-bars" id="nav-toggle-bars"></i></h4>
<input type="checkbox" onclick="showHideNavToggle(event)" id="nav-toggle" class="nav-toggle">
</div>
</div>
<label for="nav-toggle" class="nav-toggle-label">
<span></span>
</label>
</div>
<div class="navbar">
<div class="nav-links" id="myTopnav">
<ul>
<li a href="#">Food</li>
<li a href="#">Drink</li>
<li a href="#">Covid-19</li>
<li a href="#">News</li>
<li a href="#">Join the Team</li>
</ul>
</div>
</div>
<div class="contents1">
<img src="https://mcdn.wallpapersafari.com/medium/84/3/pQuUz4.jpg" class="bluepic" alt="Blue">
</div>
<div class="footer">
<div class="info">
Leave us a review:
<i class="fab fa-tripadvisor"></i>
</div>
<div class="socialiconsf">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
<div class="footer2">
<p>
© The Blue Lion 2021
</p>
</div>
Note:
I also corrected 2 html closing tags (one </div> eliminated and </h4> closing tag corrected and replaced img source with a link to a generic blue background)
See this response in codepen.
https://codepen.io/threefingers/pen/PojZMpx
Add in your ::before element icon, the code icons in your states.
.mydiv{
background-color: blue;
height: 50px;
width: 50px;
}
input + .mydiv::before{
content: 'code icon 1';
}
input:checked + .mydiv::before{
content: 'code icon 2';
}
<input type="checkbox" value="Car"> I have a car
<div class="mydiv"></div>

Adding link to logo adds link to whole navbar

I added a link to the logo(image) on the navbar, but when I go to the page the whole navbar apart from the links becomes the link. How do I make it so that it only applies to the image?
As per comments I have uipdated the code with CSS and JS. I'm very new to web development, this may explain my lack of knowledge and overuse of CSS.
the image.
function navHamburger() {
var x = document.getElementById("nav-links");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
nav {
background-color: #fff;
}
.nav-row {
/* margin: 0; */
overflow: hidden;
position: relative;
padding: 10px;
}
.nav-row #nav-links {
display: none;
}
.nav-row a {
color: #0075b2;
text-decoration: none;
font-weight: 500;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
text-align: center;
text-transform: uppercase;
padding: 20px;
}
.nav-row a.icon {
font-size: 200%;
display: block;
position: absolute;
right: 0;
top: 0;
margin-top: 0.1em;
margin-right: 25px;
}
.nav-row a:hover {
color: #19afff;
}
.main-nav {
text-decoration: none;
list-style: none;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
}
.mobile-menu {
text-decoration: none;
list-style: none;
}
.main-nav li a:link,
.main-nav li a:visited {
color: #0075b2;
text-decoration: none;
text-transform: uppercase;
font-size: 150%;
font-weight: 500;
padding: 4px;
}
.main-nav li a:hover,
.main-nav li a:active {
border-top: 2px solid #b36500;
border-bottom: 2px solid #b36500;
-webkit-transition: border-bottom 0.2s;
-o-transition: border-bottom 0.2s;
transition: border-bottom 0.2s;
}
#media (min-width: 601px) {
.mobile-menu {
display: none;
}
}
.desktop-menu {
display: none;
right: 0;
top: 0;
}
#media (min-width: 601px) {
.desktop-menu {
display: block;
position: absolute;
margin-top: 30px;
margin-right: 10px;
}
.nav-row {
margin-right: 20px;
}
.nav-row a {
margin-left: 20px;
}
}
#media (min-width: 901px) {
.desktop-menu {
margin-top: 50px;
margin-right: 10px;
}
}
#media (min-width: 1290px) {
.desktop-menu {
margin-top: 70px;
margin-right: 10px;
}
}
<nav>
<div class="nav-row">
<div>
<a href="index.html">
<img
src="resources/img/logo/fullLogo.svg"
alt="Archer Civils & Construction Logo"
class="logo"
/>
</a>
</div>
<div class="mobile-menu">
<div id="nav-links">
Civils
Fencing
Contact
</div>
<a
href="javascript:void(0);"
class="icon hamburger-icon"
onclick="navHamburger()"
>
<i class="fa fa-bars"></i>
</a>
</div>
<div class="desktop-menu">
<ul class="main-nav">
<li>Civils</li>
<li>Fencing</li>
<li>Contact </li>
</ul>
</div>
</div>
</nav>
You're using flex for the main nav class, which takes full inline value:
fiddle to playaround.
nav {
background-color: #fff;
}
.nav-row {
/* margin: 0; */
overflow: hidden;
position: relative;
padding: 10px;
}
.nav-row #nav-links {
display: none;
}
img {
height: 100px;
width: 100px;
}
.nav-row a {
color: #0075b2;
text-decoration: none;
font-weight: 500;
text-align: center;
text-transform: uppercase;
padding: 20px;
}
.nav-row a.icon {
font-size: 200%;
display: block;
position: absolute;
right: 0;
top: 0;
margin-top: 0.1em;
margin-right: 25px;
}
.nav-row a:hover {
color: #19afff;
}
.main-nav {
text-decoration: none;
list-style: none;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
}
.mobile-menu {
text-decoration: none;
list-style: none;
}
.main-nav li a:link,
.main-nav li a:visited {
color: #0075b2;
text-decoration: none;
text-transform: uppercase;
font-size: 150%;
font-weight: 500;
padding: 4px;
}
.main-nav li a:hover,
.main-nav li a:active {
border-top: 2px solid #b36500;
border-bottom: 2px solid #b36500;
-webkit-transition: border-bottom 0.2s;
-o-transition: border-bottom 0.2s;
transition: border-bottom 0.2s;
}
#media (min-width: 601px) {
.mobile-menu {
display: none;
}
}
.desktop-menu {
display: none;
right: 0;
top: 0;
}
#media (min-width: 601px) {
.desktop-menu {
display: block;
position: absolute;
margin-top: 30px;
margin-right: 10px;
}
.nav-row {
margin-right: 20px;
}
.nav-row a {
margin-left: 20px;
}
}
#media (min-width: 901px) {
.desktop-menu {
margin-top: 50px;
margin-right: 10px;
}
}
#media (min-width: 1290px) {
.desktop-menu {
margin-top: 70px;
margin-right: 10px;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/css/bootstrap.min.css" rel="stylesheet" />
<nav>
<div class="nav-row">
<div>
<a href="index.html">
<img src="http://placekitten.com/301/301" alt="Archer Civils & Construction Logo" class="logo" />
</a>
</div>
<div class="mobile-menu">
<div id="nav-links">
Civils
Fencing
Contact
</div>
<a href="javascript:void(0);" class="icon hamburger-icon" onclick="navHamburger()">
<i class="fa fa-bars"></i>
</a>
</div>
<div class="desktop-menu">
<ul class="main-nav">
<li>Civils</li>
<li>Fencing</li>
<li>Contact </li>
</ul>
</div>
</div>
</nav>
"display:flex" is the culprit here. Due to "display:flex" css property on the link, link is taking complete line. But it is not like that other navigation items has also turned into link but because link is taking the complete width and layered above the other navigation items it must be giving feel like other navigation items has also become a same link. You can refer the below screenshot:
Here is the code of it:
<!DOCTYPE html>
<html>
<head>
<style>
.logo-link {
display: flex;
cursor: pointer
}
.logo-link img {
max-height: 200px;
}
</style>
</head>
<body>
<nav>
<a class="logo-link" href=""><img
src="https://i.pinimg.com/736x/5b/b4/8b/5bb48b07fa6e3840bb3afa2bc821b882.jpg"></a>
<div>
<ul>
<li>Item1</li>
<li>Item2</li>
</ul>
</div>
</nav>
</body>
</html>
You can create your code like this to resolve this issue:
<!DOCTYPE html>
<html>
<head>
<style>
nav {
width: 100%;
height: 100px;
background-color: bisque;
box-sizing: border-box;
display: flex;
align-items: center;
}
nav .align-left {
margin-left: 10px;
margin-right: auto;
height: 90%;
}
nav .align-right {
margin-left: auto;
margin-right: 10px;
height: 100%;
display: flex;
justify-content: space-between;
width: 11%;
height: 20%;
}
nav .logo-link>img {
height: 100%;
}
</style>
</head>
<body>
<nav>
<div class="align-left">
<a class="logo-link" href=""><img
src="https://i.pinimg.com/736x/5b/b4/8b/5bb48b07fa6e3840bb3afa2bc821b882.jpg"></a>
</div>
<div class="align-right">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
</nav>
</body>
</html>
Just insert tour image tag inside the anchor tag like this:
Text

Make tabs appear when bars icon is clicked(responsive navbar)

I created a navbar and all the tabs are inline. When the window size is reduced, a bars icon appears and the tabs display vertically instead of horizontally. I want the output so that when the window size is reduced, the bars icon appears but the tabs disappear and can only be seen (vertically) and unseen when the bars icon is clicked.
I tried jquery, but it didn't work. I'm not sure how to do this, can you help me?
body {
margin: 0;
padding: 0;
font-family: Sans-Serif;
}
nav {
margin-left: 45px;
;
width: 90%;
background: #D1D0D3;
}
ul {
list-style-type: none;
width: 80%;
margin: 0 auto;
color: black;
padding: 0;
}
ul a {
color: black;
text-decoration: none;
}
ul li {
display: inline-block;
padding: 20px;
}
ul li:hover {
background-color: yellow;
}
.toggle {
width: 100%;
padding: 10px 20px 0px 20px;
background-color: #C2ABF1;
text-align: right;
box-sizing: border-box;
color: white;
font-size: 30px;
display: none;
}
#media (max-width: 800px) {
.toggle {
display: block;
}
.block {
display: block;
}
}
<div class="toggle">
<i class="fa fa-bars menu" id="menu"></i>
</div>
<nav>
<ul class="ul">
<li class="block">Home</li>
<li class="block">About</li>
<li class="block">Makeup</li>
<li class="block">Hairstyle</li>
<li class="block">Contact</li>
</ul>
</nav>
Add this jquery code
$(".menu").on("click", function() {
$("nav .ul").toggle(500);
})
And this CSS in media query
.ul {
display: none;
}
nav {
margin-left: 0;
width: 100%;
}
$(".menu").on("click", function() {
$("nav .ul").toggle(500);
})
body {
margin: 0;
padding: 0;
font-family: Sans-Serif;
}
nav {
margin-left: 45px;
;
width: 90%;
background: #D1D0D3;
}
ul {
list-style-type: none;
width: 80%;
margin: 0 auto;
color: black;
padding: 0;
}
ul a {
color: black;
text-decoration: none;
}
ul li {
display: inline-block;
padding: 20px;
}
ul li:hover {
background-color: yellow;
}
.toggle {
width: 100%;
padding: 10px 20px 0px 20px;
background-color: #C2ABF1;
text-align: right;
box-sizing: border-box;
color: white;
font-size: 30px;
display: none;
}
#media (max-width: 800px) {
.toggle {
display: block;
}
.block {
display: block;
}
.ul {
display: none;
}
nav {
margin-left: 0;
width: 100%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://use.fontawesome.com/eed659c9d4.js"></script>
<div class="toggle">
<i class="fa fa-bars menu" id="menu"></i>
</div>
<nav>
<ul class="ul">
<li class="block">Home</li>
<li class="block">About</li>
<li class="block">Makeup</li>
<li class="block">Hairstyle</li>
<li class="block">Contact</li>
</ul>
</nav>
Your code should be like this:
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel='stylesheet' href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body{
margin: 0;
padding: 0;
font-family: Sans-Serif;
}
nav{
margin-left: 45px;;
width: 90%;
background: #D1D0D3;
}
ul{
list-style-type: none;
width: 80%;
margin: 0 auto;
color: black;
padding: 0;
}
ul a {
color: black;
text-decoration: none;
}
ul li{
display: inline-block;
padding: 20px;
}
ul li:hover{
background-color: yellow;
}
.toggle{
width: 100%;
padding: 10px 20px 0px 20px;
background-color: #C2ABF1;
text-align: right;
box-sizing: border-box;
color: white;
font-size: 30px;
display: none;
}
#media (max-width: 800px)
{
.toggle{
display: block;
}
nav ul{
display:none;
}
ul li{
display:block;
}
}
</style>
</head>
<body>
<div class="toggle">
<i class="fa fa-bars menu" id="menu"></i>
</div>
<nav>
<ul class="ul">
<li>Home</li>
<li><a href="#" >About</a></li>
<li>Makeup</li>
<li>Hairstyle</li>
<li>Contact</li>
</ul>
</nav>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(".menu").on("click", function() {
$("nav .ul").toggle();
})
</script>
</html>