I'm trying to do a basic nav-bar. This nav bar contains a "search" button.
My goal is to make a hover in the search button that makes appear an input (and moves the button to the left) for the user to search anything he wants.
The thing is: I need to make the search button move to the left when I hover the input too, and I'm not figuring it out.
And as you see with that code, the item bugs.
Here's the code:
/*----------NAV BAR----------*/
body {
margin: 0;
font-family: 'Poppins', sans-serif;
font-weight: 300;
}
.nav-backgc {
height: 140px;
position: fixed;
width: 100%;
transition: 0.4s;
z-index: 9;
backdrop-filter: blur(1rem);
background-color: #DAA520;
}
.container-nav {
width: 80%;
margin-left: 10%;
position: fixed;
z-index: inherit 9;
}
.logonav {
max-width: 65px;
padding: 10px 0px 2px 0px;
position: relative;
float: left;
margin-top: -5px;
display: none;
}
.logo {
max-width: 65px;
padding: 10px 0px 2px 0px;
}
nav {
width: 100%;
padding-bottom: 2px;
}
.navbar ul {
padding: 0;
list-style: none;
}
.navbar li {
display: inline-block;
margin: 0px 25px;
position: relative;
}
.navcarrito span {
display: none;
}
.navbar a {
text-decoration: none;
color: #fff;
}
.navbar a {
color: #fff;
}
.barra {
margin-top: 27px;
}
hr {
opacity: 20%
}
.navcarrito.login-carrito {
display: none;
font-size: 18px;
}
.navcarrito {
display: flex;
float: right;
position: fixed;
right: 20%;
margin-top: -35px;
transition: 0.3s;
}
.navlogin {
float: right;
display: flex;
position: fixed;
right: 1.5%;
margin-top: -35px;
transition: 0.3s;
}
.navlogin {
float: right;
position: fixed;
right: 1.5%;
margin-top: -35px;
transition: 0.3s;
}
.nav-arriba {
padding-top: 50px;
width: 100%;
}
.nav-arriba a {
text-decoration: none;
}
.nav-arriba ul {
padding: 0;
list-style: none;
}
.nav-arriba li {
display: inline-block;
margin: 0px 25px;
position: relative;
}
.search {
transition: 0.3s;
}
.search:hover {
margin-right: 100px;
}
.searchBuscador {
display: none;
position: absolute;
}
input:focus:hover {
margin-right: 100px;
}
.search:hover~.searchBuscador {
display: inline-block;
}
/* ==========================================================================
DROPDOWN MENU
========================================================================== */
.dropdownMenu {
position: absolute;
display: none;
width: 500px;
background-color: #fff;
border-radius: 7px;
justify-content: space-evenly;
flex-wrap: wrap;
box-shadow: 2px 2px rgba(163, 163, 163, 0.295);
}
.dropdownBoton:hover>.dropdownMenu {
display: flex;
}
.dropdownMenu a {
display: flex;
flex-direction: column;
width: 35%;
color: black;
border-radius: 5px;
margin-block-start: 0.5em;
height: 100px;
}
.dropdownMenu a h3 {
margin-block-start: 16px;
margin-block-end: -9.5px;
}
/* ==========================================================================
RESOLUCION 1200-1600
========================================================================== */
#media (min-width: 1024px) and (max-width: 1600px) {
.navlogin li a {
display: none;
}
.navcarrito span {
display: inline-block;
}
.navcarrito {
right: 6%;
}
}
#media (min-width: 1200px) and (max-width: 1300px) {
.navcarrito li {
margin: 0px 15px;
}
}
/*****RESOLUCION 1024*****/
#media (min-width:1024px) {}
/*****RESOLUCION 768*****/
#media (min-width:768px) {}
/*****RESOLUCION 480*****/
#media (min-width:480px) {}
/*****RESOLUCION 320*****/
#media (min-width:320px) {}
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link href="/stylesheets/nav.css" rel="stylesheet">
<script src="https://kit.fontawesome.com/8431526c8f.js" crossorigin="anonymous"></script>
<header>
<div id="navbar" class="nav-backgc">
<div class="container-nav">
<div class="navbar">
<center>
<img src="/images/logo2.png" alt="BierClub" class="logo">
<ul id="navcarrito" class="navcarrito">
<li class="search"><i class="fas fa-search"></i></li>
<li><i class="fas fa-shopping-cart"></i></li>
<div class="searchBuscador">
<input type="text"></input>
</div>
<span>
<li class="login-carrito"><i class="fas fa-sign-in-alt"></i></li>
</span>
</ul><strong>
<ul id="navlogin" class="navlogin">
<li><i class="fas fa-sign-in-alt"></i> Iniciar sesion</li>
</ul>
</strong>
<hr><img src="/images/logo2.png" alt="BierClub" class="logonav" id="logonav">
<nav>
<ul class="barra"><strong>
<li class="dropdownBoton">Productos
<div class="dropdownMenu">
<a href="#">
<h3>Lupuladas</h3>
<h6>Lorem ipsum dolor sit amet consectetur.</h6>
</a>
<a href="#">
<h3>No lupuladas</h3>
<h6>Lorem ipsum dolor sit amet consectetur.</h6>
</a>
</div>
</li>
<li>Promociones</li>
<li>Suscribete</li>
<li>Envio</li>
<li>¿Quienes Somos?</li>
</ul></strong>
</nav>
</center>
</div>
</div>
</div>
</header>
Answer:
Onclick javascript statement added...
function search(){
document.getElementById("search-bar").style = "display:block;";
document.getElementById("search-bar").focus() ;
}
/*----------NAV BAR----------*/
body{
margin: 0;
font-family: 'Poppins', sans-serif;
font-weight: 300;
}
.nav-backgc{
height:140px;
position: fixed;
width: 100%;
transition: 0.4s;
z-index: 9;
backdrop-filter: blur(1rem);
background-color: #DAA520;
}
.container-nav{
width : 80%;
margin-left:10%;
position:fixed;
z-index:inherit 9;
}
.logonav{
max-width: 65px;
padding: 10px 0px 2px 0px;
position: relative;
float:left;
margin-top: -5px;
display:none;
}
.logo{
max-width: 65px;
padding: 10px 0px 2px 0px;
}
nav{
width: 100%;
padding-bottom: 2px;
}
.navbar ul{
padding: 0;
list-style: none;
}
.navbar li{
display: inline-block;
margin: 0px 25px;
position: relative;
}
.navcarrito span{
display: none;
}
.navbar a{
text-decoration: none;
color: #fff;
}
.navbar a{
color: #fff;
}
.barra{
margin-top: 27px;
}
hr{
opacity:20%
}
.navcarrito.login-carrito{
display: none;
font-size: 18px;
}
.navcarrito{
display: flex;
float:right;
position: fixed;
right: 20%;
margin-top: -35px;
transition: 0.3s;
}
.navlogin{
float:right;
display:flex;
position:fixed;
right: 1.5%;
margin-top: -35px;
transition: 0.3s;
}
.navlogin{
float:right;
position:fixed;
right: 1.5%;
margin-top: -35px;
transition: 0.3s;
}
.nav-arriba{
padding-top: 50px;
width: 100%;
}
.nav-arriba a{
text-decoration: none;
}
.nav-arriba ul{
padding: 0;
list-style: none;
}
.nav-arriba li{
display: inline-block;
margin: 0px 25px;
position: relative;
}
.search{
transition: 0.3s;
}
.search:hover{
/* margin-right: 100px; */
}
.searchBuscador1{
display:block;
position:absolute;
}
#search-bar{
display:none;
}
input:focus:hover{
/* margin-right: 100px;*/
}
.search:focus .searchBuscador{
/* display: inline-block;*/
display:block;
}
/* ==========================================================================
DROPDOWN MENU
========================================================================== */
.dropdownMenu{
position: absolute;
display: none;
width: 500px;
background-color: #fff;
border-radius: 7px;
justify-content: space-evenly;
flex-wrap: wrap;
box-shadow: 2px 2px rgba(163, 163, 163, 0.295);
}
.dropdownBoton:hover > .dropdownMenu{
display:flex;
}
.dropdownMenu a{
display: flex;
flex-direction: column;
width: 35%;
color: black;
border-radius: 5px;
margin-block-start: 0.5em;
height: 100px;
}
.dropdownMenu a h3{
margin-block-start: 16px;
margin-block-end: -9.5px;
}
/* ==========================================================================
RESOLUCION 1200-1600
========================================================================== */
#media (min-width: 1024px) and (max-width: 1600px) {
.navlogin li a{
display:none;
}
.navcarrito span{
display: inline-block;
}
.navcarrito{
right: 6%;
}
}
#media (min-width: 1200px) and (max-width: 1300px) {
.navcarrito li{
margin: 0px 15px;
}
}
/*****RESOLUCION 1024*****/
#media (min-width:1024px) {
}
/*****RESOLUCION 768*****/
#media (min-width:768px) {
}
/*****RESOLUCION 480*****/
#media (min-width:480px) {
}
/*****RESOLUCION 320*****/
#media (min-width:320px) {
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>navbar</title>
<link rel="icon" href="/images/faviconLogo.ico"/>
<script type="text/javascript" src="/js/speak.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link href="/stylesheets/nav.css" rel="stylesheet">
<script src="https://kit.fontawesome.com/8431526c8f.js" crossorigin="anonymous"></script>
</head>
<style>
/**Style Sheet - CSS **/
</style>
<body>
<header>
<div id="navbar" class="nav-backgc">
<div class ="container-nav">
<div class ="navbar">
<center>
<img src="/images/logo2.png" alt="BierClub" class="logo">
<ul id ="navcarrito" class="navcarrito">
<li class="search"><a href="#"><i class="fas fa-search" onclick="search()" ></i><!/a></li>
<div class="searchBuscador">
<input type="text" onblur="this.style='display:none;'"
id="search-bar"></input>
</div>
<li><i class="fas fa-shopping-cart"></i></li>
<span><li class="login-carrito"><i class="fas fa-sign-in-alt"></i></li></span>
</ul><strong>
<ul id ="navlogin" class="navlogin">
<li><i class="fas fa-sign-in-alt"></i> Iniciar sesion</li>
</ul></strong>
<hr><img src="/images/logo2.png" alt="BierClub" class="logonav" id="logonav">
<nav>
<ul class="barra"><strong>
<li class="dropdownBoton">Productos
<div class="dropdownMenu">
<a href="#">
<h3>Lupuladas</h3>
<h6>Lorem ipsum dolor sit amet consectetur.</h6>
</a>
<a href="#">
<h3>No lupuladas</h3>
<h6>Lorem ipsum dolor sit amet consectetur.</h6>
</a>
</div>
</li>
<li>Promociones</li>
<li>Suscribete</li>
<li>Envio</li>
<li>¿Quienes Somos?</li>
</ul></strong>
</nav>
</center>
</div>
</div>
</div>
</header>
<script>
/** Javascript **/
</script>
</body>
</html>
Hover Effect..
/*----------NAV BAR----------*/
body{
margin: 0;
font-family: 'Poppins', sans-serif;
font-weight: 300;
}
.nav-backgc{
height:140px;
position: fixed;
width: 100%;
transition: 0.4s;
z-index: 9;
backdrop-filter: blur(1rem);
background-color: #DAA520;
}
.container-nav{
width : 80%;
margin-left:10%;
position:fixed;
z-index:inherit 9;
}
.logonav{
max-width: 65px;
padding: 10px 0px 2px 0px;
position: relative;
float:left;
margin-top: -5px;
display:none;
}
.logo{
max-width: 65px;
padding: 10px 0px 2px 0px;
}
nav{
width: 100%;
padding-bottom: 2px;
}
.navbar ul{
padding: 0;
list-style: none;
}
.navbar li{
display: inline-block;
margin: 0px 25px;
position: relative;
}
.navcarrito span{
display: none;
}
.navbar a{
text-decoration: none;
color: #fff;
}
.navbar a{
color: #fff;
}
.barra{
margin-top: 27px;
}
hr{
opacity:20%
}
.navcarrito.login-carrito{
display: none;
font-size: 18px;
}
.navcarrito{
display: flex;
float:right;
position: fixed;
right: 20%;
margin-top: -35px;
transition: 0.3s;
}
.navlogin{
float:right;
display:flex;
position:fixed;
right: 1.5%;
margin-top: -35px;
transition: 0.3s;
}
.navlogin{
float:right;
position:fixed;
right: 1.5%;
margin-top: -35px;
transition: 0.3s;
}
.nav-arriba{
padding-top: 50px;
width: 100%;
}
.nav-arriba a{
text-decoration: none;
}
.nav-arriba ul{
padding: 0;
list-style: none;
}
.nav-arriba li{
display: inline-block;
margin: 0px 25px;
position: relative;
}
.search{
transition: 0.3s;
}
.search:hover{
/* margin-right: 100px; */
}
.searchBuscador{
display:none;/*
position:absolute;*/
}
input:focus{
/* margin-right: 100px;*/
display:block;
}
.search:hover ~ .searchBuscador{
/* display: inline-block;*/
display:block;
}
/* ==========================================================================
DROPDOWN MENU
========================================================================== */
.dropdownMenu{
position: absolute;
display: none;
width: 500px;
background-color: #fff;
border-radius: 7px;
justify-content: space-evenly;
flex-wrap: wrap;
box-shadow: 2px 2px rgba(163, 163, 163, 0.295);
}
.dropdownBoton:hover > .dropdownMenu{
display:flex;
}
.dropdownMenu a{
display: flex;
flex-direction: column;
width: 35%;
color: black;
border-radius: 5px;
margin-block-start: 0.5em;
height: 100px;
}
.dropdownMenu a h3{
margin-block-start: 16px;
margin-block-end: -9.5px;
}
/* ==========================================================================
RESOLUCION 1200-1600
========================================================================== */
#media (min-width: 1024px) and (max-width: 1600px) {
.navlogin li a{
display:none;
}
.navcarrito span{
display: inline-block;
}
.navcarrito{
right: 6%;
}
}
#media (min-width: 1200px) and (max-width: 1300px) {
.navcarrito li{
margin: 0px 15px;
}
}
/*****RESOLUCION 1024*****/
#media (min-width:1024px) {
}
/*****RESOLUCION 768*****/
#media (min-width:768px) {
}
/*****RESOLUCION 480*****/
#media (min-width:480px) {
}
/*****RESOLUCION 320*****/
#media (min-width:320px) {
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>navbar</title>
<link rel="icon" href="/images/faviconLogo.ico"/>
<script type="text/javascript" src="/js/speak.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link href="/stylesheets/nav.css" rel="stylesheet">
<script src="https://kit.fontawesome.com/8431526c8f.js" crossorigin="anonymous"></script>
</head>
<body>
<header>
<div id="navbar" class="nav-backgc">
<div class ="container-nav">
<div class ="navbar">
<center>
<img src="/images/logo2.png" alt="BierClub" class="logo">
<ul id ="navcarrito" class="navcarrito">
<li class="search"><i class="fas fa-search" ></i></li>
<div class="searchBuscador">
<input type="txt" >
</div>
<li><i class="fas fa-shopping-cart"></i></li>
<span><li class="login-carrito"><i class="fas fa-sign-in-alt"></i></li></span>
</ul><strong>
<ul id ="navlogin" class="navlogin">
<li><i class="fas fa-sign-in-alt"></i> Iniciar sesion</li>
</ul></strong>
<hr><img src="/images/logo2.png" alt="BierClub" class="logonav" id="logonav">
<nav>
<ul class="barra"><strong>
<li class="dropdownBoton">Productos
<div class="dropdownMenu">
<a href="#">
<h3>Lupuladas</h3>
<h6>Lorem ipsum dolor sit amet consectetur.</h6>
</a>
<a href="#">
<h3>No lupuladas</h3>
<h6>Lorem ipsum dolor sit amet consectetur.</h6>
</a>
</div>
</li>
<li>Promociones</li>
<li>Suscribete</li>
<li>Envio</li>
<li>¿Quienes Somos?</li>
</ul></strong>
</nav>
</center>
</div>
</div>
</div>
</header>
</body>
</html>
Related
I was just creating website with html and CSS with a responsive navigation bar and hamburger menu
and which has some content as well in the body of page
but after including contents inside the page the hamburger menu isn't showing
its transition are only you can see
i just wanted the hamburger menu to be shown without disturbing the contents of this page
code
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background-color: #2f2f42;
}
nav {
display: flex;
height: 90px;
width: 100%;
align-items: center;
justify-content: space-between;
padding: 0 50px 0 100px;
flex-wrap: wrap;
}
nav .logo {
font-size: 20px;
font-weight: bold;
color: teal;
}
nav ul {
display: flex;
flex-wrap: wrap;
list-style: none;
}
nav ul li {
margin: 0 5px;
}
nav ul li a {
color: rgb(92, 156, 92);
text-decoration: none;
font-size: 18px;
font-weight: 500;
padding: 8px 15px;
border-radius: 5px;
letter-spacing: 1px;
transition: all 0.3s ease;
}
nav ul li a.active,
nav ul li a:hover {
color: teal;
background-color: white;
}
nav .menu-btn i {
color: #fff;
font-size: 22px;
cursor: pointer;
display: none;
}
input[type="checkbox"] {
display: none;
}
#media (max-width: 1000px) {
nav {
padding: 0 40px 0 50px;
}
}
#media (max-width: 920px) {
nav .menu-btn i {
display: block;
}
#click:checked~.menu-btn i:before {
content: "\f00d";
}
nav ul {
position: fixed;
top: 80px;
left: -100%;
height: 100vh;
width: 100%;
text-align: center;
display: block;
transition: all 0.3s ease;
}
#click:checked~ul {
left: 0;
}
nav ul li {
width: 100%;
margin: 40px 0;
}
nav ul li a {
width: 100%;
margin-left: -100%;
display: block;
font-size: 20px;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
#click:checked~ul li a {
margin-left: 0px;
}
nav ul li a.active,
nav ul li a:hover {
background: none;
color: teal;
}
}
.content {
position: relative;
background-color: #131314;
color: whitesmoke;
border: 5px solid grey;
border-radius: 12px;
width: auto;
height: 50rem;
margin-top: 1vw;
margin-left: 4vw;
margin-right: 4vw;
font-weight: bolder;
}
#media (max-width: 920px) {
.content {
display: block;
}
}
#media (max-width: 920px) {
.content #bor,
.det,
.clk {
display: block;
}
}
.bor {
justify-content: center;
text-align: center;
border-bottom: 0.7vw solid white;
}
.det {
display: inline-block;
margin-left: 1vw;
text-align: left;
border-bottom: 0.6vw solid whitesmoke;
}
.clk {
float: right;
width: fit-content;
height: fit-content;
margin-right: 1vw;
}
h2 {
box-sizing: border-box;
padding: 0.6vw;
margin: 0.8vw 0.8vw 0.8vw 0.8vw;
background-color: rgb(64, 80, 113);
text-align: left
}
#exp {
padding: 0.8vw;
margin: 0.8vw 0.8vw 0.8vw 1.9vw;
text-align: left;
}
footer {
background-color: rgb(104, 99, 25);
color: black;
margin: 15px;
padding: 15px;
border-radius: 8px;
}
#foo {
text-align: center;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Navigation Menu</title>
</head>
<body>
<nav>
<div class="logo">Logo img</div>
<input type="checkbox" id="click">
<label for="click" class="menu-btn">
<i class="fas fa-bars"></i>
</label>
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Services</li>
<li>About</li>
</ul>
</nav>
<div class="content">
<p class="bor"> this is content heading <br>
</p><br>
<span class="det">this is content side</span> <button class="clk">Watch</button><br><br>
<span class="det">this is content side</span><button class="clk">Watch</button><br><br><br>
<h2>this is demo</h2>
<p id="exp">this is content end</p>
</div>
<div id="foo">
<footer>
<p>Copyright © company 2022<br><br> All Rights Reserved</p>
</footer>
</div>
</body>
</html>
Simply add a z-index: 9999; to your nav ul and will see that.
It is hidden probably because it is out of the overflow of the parent block.
Try to add a background-color: #2f2f42; to your ul and job should be done.
DEMO
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background-color: #2f2f42;
}
nav {
display: flex;
height: 90px;
width: 100%;
align-items: center;
justify-content: space-between;
padding: 0 50px 0 100px;
flex-wrap: wrap;
}
nav .logo {
font-size: 20px;
font-weight: bold;
color: teal;
}
nav ul {
display: flex;
flex-wrap: wrap;
list-style: none;
}
nav ul li {
margin: 0 5px;
}
nav ul li a {
color: rgb(92, 156, 92);
text-decoration: none;
font-size: 18px;
font-weight: 500;
padding: 8px 15px;
border-radius: 5px;
letter-spacing: 1px;
transition: all 0.3s ease;
}
nav ul li a.active,
nav ul li a:hover {
color: teal;
background-color: white;
}
nav .menu-btn i {
color: #fff;
font-size: 22px;
cursor: pointer;
display: none;
}
input[type="checkbox"] {
display: none;
}
#media (max-width: 1000px) {
nav {
padding: 0 40px 0 50px;
}
}
#media (max-width: 920px) {
nav .menu-btn i {
display: block;
}
#click:checked~.menu-btn i:before {
content: "\f00d";
}
nav ul {
position: fixed;
top: 80px;
left: -100%;
z-index: 9999; /** ADDED **/
height: 100vh;
width: 100%;
text-align: center;
display: block;
transition: all 0.3s ease;
background-color: #2f2f42; /** ADDED **/
}
#click:checked~ul {
left: 0;
}
nav ul li {
width: 100%;
margin: 40px 0;
}
nav ul li a {
width: 100%;
margin-left: -100%;
display: block;
font-size: 20px;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
#click:checked~ul li a {
margin-left: 0px;
}
nav ul li a.active,
nav ul li a:hover {
background: none;
color: teal;
}
}
.content {
position: relative;
background-color: #131314;
color: whitesmoke;
border: 5px solid grey;
border-radius: 12px;
width: auto;
height: 50rem;
margin-top: 1vw;
margin-left: 4vw;
margin-right: 4vw;
font-weight: bolder;
}
#media (max-width: 920px) {
.content {
display: block;
}
}
#media (max-width: 920px) {
.content #bor,
.det,
.clk {
display: block;
}
}
.bor {
justify-content: center;
text-align: center;
border-bottom: 0.7vw solid white;
}
.det {
display: inline-block;
margin-left: 1vw;
text-align: left;
border-bottom: 0.6vw solid whitesmoke;
}
.clk {
float: right;
width: fit-content;
height: fit-content;
margin-right: 1vw;
}
h2 {
box-sizing: border-box;
padding: 0.6vw;
margin: 0.8vw 0.8vw 0.8vw 0.8vw;
background-color: rgb(64, 80, 113);
text-align: left
}
#exp {
padding: 0.8vw;
margin: 0.8vw 0.8vw 0.8vw 1.9vw;
text-align: left;
}
footer {
background-color: rgb(104, 99, 25);
color: black;
margin: 15px;
padding: 15px;
border-radius: 8px;
}
#foo {
text-align: center;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Navigation Menu</title>
</head>
<body>
<nav>
<div class="logo">Logo img</div>
<input type="checkbox" id="click">
<label for="click" class="menu-btn">
<i class="fas fa-bars"></i>
</label>
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Services</li>
<li>About</li>
</ul>
</nav>
<div class="content">
<p class="bor"> this is content heading <br>
</p><br>
<span class="det">this is content side</span> <button class="clk">Watch</button><br><br>
<span class="det">this is content side</span><button class="clk">Watch</button><br><br><br>
<h2>this is demo</h2>
<p id="exp">this is content end</p>
</div>
<div id="foo">
<footer>
<p>Copyright © company 2022<br><br> All Rights Reserved</p>
</footer>
</div>
</body>
</html>
I'm trying to add a header on top of this image with a gradient that I've made but it gives me a weird white background as such https://i.stack.imgur.com/ppuJq.png I want the text on top of the image to have a transparent background. Made the navbar black so its easier to see but anyway, how do I remove it? I am aware that the js script is unfinished if that has anything to do with it.
here is my code
/*
CSS for the page:
*/
* {
margin: 0;
}
.WelcomeMenu h1 {
font-size: 50px;
}
.WelcomeMenu img {
width: 100%;
height: 85vh;
}
.img-gradient {
position: absolute;
width: 100%;
height: 85vh;
}
.img-gradient::after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 85vh;
background: linear-gradient(rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.85));
}
.MiddleMenu {
color: #FFFF;
height: 600vh;
}
/*
CSS for navbar:
*/
body {
font-family: 'Noto Sans', sans-serif;
}
img {
width: 600px;
margin-left: 0;
margin-top: 0;
margin-bottom: 50px;
}
nav {
align-items: center;
padding: 20px;
display: flex;
justify-content: space-between;
background-color: #000;
transition-duration: 0.3s;
transition-timing-function: linear;
transition-delay: 0.1s;
}
nav .fa {
display: none;
}
nav:hover {
opacity: 100;
}
.nav-list .active {
color: #F10000;
opacity: 1;
}
.nav-list img {
width: 110px;
margin-left: -40px;
margin-top: -30px;
margin-bottom: -35px;
}
.nav-list {
text-align: right;
}
.nav-list ul li {
list-style: none;
display: inline-block;
padding: 2px 20px;
position: relative;
}
.nav-list ul li a {
text-decoration: none;
color: #F10000;
font-size: 20px;
opacity: 1;
}
.nav-list ul li::after {
content: '';
width: 0%;
height: 4px;
background: #C5C6C7;
display: block;
margin: auto;
transition: 0.6s;
}
.nav-list ul li:hover::after {
width: 100%;
}
#media (max-width: 700px) {
.nav-list ul li {
display: block;
}
.nav-list {
position: absolute;
background: black;
height: 125vh;
width: 175px;
top: 0;
right: -300px;
text-align: left;
z-index: 2;
transition: 1s;
}
.nav-list ul li a {
font-size: 15px;
}
.nav-list ul li {
padding: 20px;
}
nav .fa {
display: block;
color: white;
margin: 10px;
font-size: 20px;
cursor: pointer;
padding-left: 10px;
padding-top: 5px;
}
}
<!-- Bootstrap-4 -->
<title> Lookout </title>
<link rel="preconnect" href="https://fonts.googleapis.com/%22%3E">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght#0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Body -->
<section class="header">
<nav>
<div class="nav-list" id="navList">
<i class="fa fa-times" onclick="hideMenu()"></i>
<ul>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAAAA </li>
<img src="Bilder/Medietilsynet.png">
</ul>
</div>
<i class="fa fa-bars" onclick="showMenu()"></i>
</nav>
</section>
<section>
<div class="WelcomeMenu">
<h1> STOP THINK & CHECK. </H1>
<div class="img-gradient">
<img src="https://sites.google.com/site/quackquackquest/_/rsrc/1469302829712/duck-duck-maps/duck%20banner%203.jpg">
</div>
</div>
</section>
<section>
<div class="MiddleMenu">
</div>
</section>
It's because of the background color on body tag and the transparent background on .WelcomeMenu. Ways to fix (Only one of them):
Add a background color to .WelcomeMenu
Have a parent element and set the background color to black
Make the background color of body black
/*
CSS for the page:
*/
* {
margin: 0;
}
.WelcomeMenu {
background-color: red
}
.WelcomeMenu h1 {
font-size: 50px;
}
.WelcomeMenu img {
width: 100%;
height: 85vh;
}
.img-gradient {
position: absolute;
width: 100%;
height: 85vh;
}
.img-gradient::after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 85vh;
background: linear-gradient(rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.85));
}
.MiddleMenu {
color: #FFFF;
height: 600vh;
}
/*
CSS for navbar:
*/
body {
font-family: 'Noto Sans', sans-serif;
}
img {
width: 600px;
margin-left: 0;
margin-top: 0;
margin-bottom: 50px;
}
nav {
align-items: center;
padding: 20px;
display: flex;
justify-content: space-between;
background-color: #000;
transition-duration: 0.3s;
transition-timing-function: linear;
transition-delay: 0.1s;
}
nav .fa {
display: none;
}
nav:hover {
opacity: 100;
}
.nav-list .active {
color: #F10000;
opacity: 1;
}
.nav-list img {
width: 110px;
margin-left: -40px;
margin-top: -30px;
margin-bottom: -35px;
}
.nav-list {
text-align: right;
}
.nav-list ul li {
list-style: none;
display: inline-block;
padding: 2px 20px;
position: relative;
}
.nav-list ul li a {
text-decoration: none;
color: #F10000;
font-size: 20px;
opacity: 1;
}
.nav-list ul li::after {
content: '';
width: 0%;
height: 4px;
background: #C5C6C7;
display: block;
margin: auto;
transition: 0.6s;
}
.nav-list ul li:hover::after {
width: 100%;
}
#media (max-width: 700px) {
.nav-list ul li {
display: block;
}
.nav-list {
position: absolute;
background: black;
height: 125vh;
width: 175px;
top: 0;
right: -300px;
text-align: left;
z-index: 2;
transition: 1s;
}
.nav-list ul li a {
font-size: 15px;
}
.nav-list ul li {
padding: 20px;
}
nav .fa {
display: block;
color: white;
margin: 10px;
font-size: 20px;
cursor: pointer;
padding-left: 10px;
padding-top: 5px;
}
}
<!-- Bootstrap-4 -->
<title> Lookout </title>
<link rel="preconnect" href="https://fonts.googleapis.com/%22%3E">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght#0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Body -->
<section class="header">
<nav>
<div class="nav-list" id="navList">
<i class="fa fa-times" onclick="hideMenu()"></i>
<ul>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAAAA </li>
<img src="Bilder/Medietilsynet.png">
</ul>
</div>
<i class="fa fa-bars" onclick="showMenu()"></i>
</nav>
</section>
<section>
<div class="WelcomeMenu">
<h1> STOP THINK & CHECK. </H1>
<div class="img-gradient">
<img src="https://sites.google.com/site/quackquackquest/_/rsrc/1469302829712/duck-duck-maps/duck%20banner%203.jpg">
</div>
</div>
</section>
<section>
<div class="MiddleMenu">
</div>
</section>
The image that you are using is a background image! so for a better solution you can make it the background of the div.WelcomeMenu.
The white color is the background of the page (by default - which is blank white page). and the order of the elements is:
Navbar - black background
h1 - the background of the page
img - the image itself
that means, the h1 is between the two elements.
In case you still want the elements as they are, you can simply add:
.WelcomeMenu {
position: relative;
}
.WelcomeMenu h1 {
color: #ffffff;
font-size: 50px;
position: absolute;
top: 100px; (change it as you wish)
left: 100px; (change it as you wish)
}
The Code:
/*
CSS for the page:
*/
* {
margin: 0;
}
.WelcomeMenu {
position: relative;
height: 85vh;
width: 100%;
background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
url("https://sites.google.com/site/quackquackquest/_/rsrc/1469302829712/duck-duck-maps/duck%20banner%203.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.WelcomeMenu h1 {
color: #ffffff;
font-size: 50px;
}
.MiddleMenu {
color: #FFFF;
height: 600vh;
}
/*
CSS for navbar:
*/
body {
font-family: 'Noto Sans', sans-serif;
}
img {
width: 600px;
margin-left: 0;
margin-top: 0;
margin-bottom: 50px;
}
nav {
align-items: center;
padding: 20px;
display: flex;
justify-content: space-between;
background-color: #000;
transition-duration: 0.3s;
transition-timing-function: linear;
transition-delay: 0.1s;
}
nav .fa {
display: none;
}
nav:hover {
opacity: 100;
}
.nav-list .active {
color: #F10000;
opacity: 1;
}
.nav-list img {
width: 110px;
margin-left: -40px;
margin-top: -30px;
margin-bottom: -35px;
}
.nav-list {
text-align: right;
}
.nav-list ul li {
list-style: none;
display: inline-block;
padding: 2px 20px;
position: relative;
}
.nav-list ul li a {
text-decoration: none;
color: #F10000;
font-size: 20px;
opacity: 1;
}
.nav-list ul li::after {
content: '';
width: 0%;
height: 4px;
background: #C5C6C7;
display: block;
margin: auto;
transition: 0.6s;
}
.nav-list ul li:hover::after {
width: 100%;
}
#media (max-width: 700px) {
.nav-list ul li {
display: block;
}
.nav-list {
position: absolute;
background: black;
height: 125vh;
width: 175px;
top: 0;
right: -300px;
text-align: left;
z-index: 2;
transition: 1s;
}
.nav-list ul li a {
font-size: 15px;
}
.nav-list ul li {
padding: 20px;
}
nav .fa {
display: block;
color: white;
margin: 10px;
font-size: 20px;
cursor: pointer;
padding-left: 10px;
padding-top: 5px;
}
}
<!-- Bootstrap-4 -->
<title> Lookout </title>
<link rel="preconnect" href="https://fonts.googleapis.com/%22%3E">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght#0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Body -->
<section class="header">
<nav>
<div class="nav-list" id="navList">
<i class="fa fa-times" onclick="hideMenu()"></i>
<ul>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAA </li>
<li> AAAAAA </li>
<img src="Bilder/Medietilsynet.png">
</ul>
</div>
<i class="fa fa-bars" onclick="showMenu()"></i>
</nav>
</section>
<section>
<div class="WelcomeMenu">
<h1> STOP THINK & CHECK. </h1>
</div>
</section>
some device like iMac it look perfect but some i see white box in other pc.in tablet and mobile screen gets auto zoom its not fit to device i have to zoom out which makes content small.
* {
list-style: none;
text-decoration: none;
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #f7f7f7;
color: #545454;
}
/* NAVIGATION */
.navbar {
width: 100%;
height: 150px;
background: black;
position: fixed;
top: 0;
left: 0;
padding: 0 25px;
}
.navbar .inner_navbar {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 100%;
}
.navbar .hamburger {
display: none;
}
.navbar .menu ul {
display: flex;
}
.navbar .menu ul li a {
display: block;
width: 120px;
margin-right: 10px;
text-align: center;
font-size: 14px;
text-transform: uppercase;
color: #fff;
padding: 10px;
border-radius: 25px;
letter-spacing: 2px;
transition: all 0.2s ease;
}
.navbar .menu ul li:last-child a {
margin-right: 0;
}
.navbar .menu ul li a:hover,
.navbar .menu ul li a.active {
background: #5db485;
}
.container {
margin-top: 150px;
width: 1906px;
height: 397px;
}
.promo {
width: 1906px;
}
/* Safari Tours*/
.safari-tours {
background: linear-gradient(to bottom, #65214a, #8d2353, #b52455, #db2c4f, #fd3f41);
;
width: 1906px;
}
.safari-title {
text-align: center;
padding-top: 30px;
font-size: 50px;
}
.banner {
display: flex;
justify-content: center;
}
.safari {
margin: 2%;
}
.safari img {
width: 500px;
}
/*Tablet*/
#media (max-width: 992px) {
.navbar {
height: 218px;
padding: 12px;
}
.navbar .inner_navbar {
flex-direction: column;
}
.container {
margin-top: 218px;
}
}
/*Mobile*/
#media (max-width: 728px) {
.navbar {
height: 150px;
}
.navbar .inner_navbar {
flex-direction: row;
}
.navbar .menu ul {
position: absolute;
top: 150px;
left: 0;
display: block;
background: orangered;
width: 100%;
}
.navbar .menu ul li {
padding: 10px;
}
.navbar .menu ul li a {
width: 100%;
padding: 12px;
}
.navbar .hamburger {
display: block;
position: absolute;
top: 15px;
right: 25px;
color: #fff;
font-size: 24px;
cursor: pointer;
transition: all 0.2s ease;
}
.navbar .menu {
display: none;
}
.navbar .menu.activate {
display: block;
}
.container {
margin-top: 150px;
width: 690px;
height: 144px;
}
.promo {
width: 690px;
}
.safari-tours {
background: linear-gradient(to bottom, #65214a, #8d2353, #b52455, #db2c4f, #fd3f41);
width: 690px;
}
.safari {
margin: 1%;
}
.safari img {
width: 300px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="wrapper">
<div class="navbar">
<div class="inner_navbar">
<div class="logo">
<img src="/images/Final Logo.png" style="width: 150px;">
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Desert Safari</li>
<li>Tours</li>
<li>Activities</li>
<li>Contact-Us</li>
</ul>
</div>
</div>
<div class="hamburger">
<img src="/images/menu-btn.png" style="width: 40px;">
</div>
</div>
<div class="container">
<img class="promo" src="https://www.arabian-adventures.com/on/demandware.static/-/Sites-dnata-UAE-Library/default/dw922d22bf/images/slider/luxury-desert-camping-arabian-adventures-1920x400.jpg" alt="">
</div>
</div>
</header>
<section>
<div class="safari-tours">
<h1 class="safari-title">SAFARI TOURS</h1>
<div class="banner">
<div class="safari">
<img src="https://i.imgur.com/9QH8NFE.jpeg" alt="Morning Safari" />
</a>
</div>
<div class="safari">
<a href="https://bigdunestours.com/desert-safari" target="_top">
<img src="https://i.imgur.com/2E9ytwc.jpeg" alt="Evening Safari" />
</a>
</div>
</div>
</div>
</section>
<script>
var hamburger = document.querySelector(".hamburger");
var menu = document.querySelector(".menu");
hamburger.addEventListener("click", function() {
menu.classList.toggle("activate");
})
</script>
</body>
</html>
some device like iMac it look perfect but some i see white box in other pc.in tablet and mobile screen gets auto zoom its not fit to device i have to zoom out which makes content small.
edited i did try as one of the comment mention but still no luckk the results are something like this
*{
list-style: none;
text-decoration: none;
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background: #f7f7f7;
color: #545454;
}
/* NAVIGATION */
.navbar{
width: 100%;
height: 150px;
background: black;
position: fixed;
top: 0;
left: 0;
padding: 0 25px;
}
.navbar .inner_navbar{
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 100%;
}
.navbar .hamburger{
display: none;
}
.navbar .menu ul{
display: flex;
}
.navbar .menu ul li a{
display: block;
width: 120px;
margin-right: 10px;
text-align: center;
font-size: 14px;
text-transform: uppercase;
color: #fff;
padding: 10px;
border-radius: 25px;
letter-spacing: 2px;
transition: all 0.2s ease;
}
.navbar .menu ul li:last-child a{
margin-right: 0;
}
.navbar .menu ul li a:hover,
.navbar .menu ul li a.active{
background: #5db485;
}
.container{
width: 100%;
max-width: 1906;
}
/*Tablet*/
#media (max-width: 992px){
.navbar{
height: 218px;
padding: 12px;
}
.navbar .inner_navbar{
flex-direction: column;
}
.container {
max-width: 991.98px;
}
}
/*Mobile*/
#media (max-width: 728px){
.navbar{
height: 150px;
}
.navbar .inner_navbar{
flex-direction: row;
}
.navbar .menu ul{
position: absolute;
top: 150px;
left: 0;
display: block;
background: orangered;
width: 100%;
}
.navbar .menu ul li{
padding: 10px;
}
.navbar .menu ul li a{
width: 100%;
padding: 12px;
}
.navbar .hamburger{
display: block;
position: absolute;
top: 15px;
right: 25px;
color: #fff;
font-size: 24px;
cursor: pointer;
transition: all 0.2s ease;
}
.navbar .menu{
display: none;
}
.navbar .menu.activate{
display: block;
}
.container{
max-width: 727.98px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="navbar">
<div class="inner_navbar">
<div class="logo">
<img src="/images/Final Logo.png" style="width: 150px;">
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Desert Safari</li>
<li>Tours</li>
<li>Activities</li>
<li>Contact-Us</li>
</ul>
</div>
</div>
<div class="hamburger">
<img src="/images/menu-btn.png" style="width: 40px;">
</div>
<div class="container">
<img class="promo" src="https://www.arabian-adventures.com/on/demandware.static/-/Sites-dnata-UAE-Library/default/dw922d22bf/images/slider/luxury-desert-camping-arabian-adventures-1920x400.jpg" alt="">
</div>
</div>
</div>
<script>
var hamburger = document.querySelector(".hamburger");
var menu = document.querySelector(".menu");
hamburger.addEventListener("click", function(){
menu.classList.toggle("activate");
})
</script>
</body>
</html>
Use 100% width and set a max-width for each #media.
Important: use % in your main layout, not absolute pixels.
By using this the content will not overflow the .container
.container {
width: 100%;
max-width: 1906px;
}
#media (max-width: 992px) {
.container {
/* width 100% is set aboven*/
max-width: 991.98px;
}
}
#media (max-width: 728px) {
.container {
/* width 100% is set aboven*/
max-width: 727.98px;
}
}
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>
In the mobile version (width max 411px) when I create a navbar and I use absolute position when the dropdown active, why the background color don't cover all the element inside nav div?
Codepen <<-- Here's the codepen version
I've using overflow hidden and still doesn't work
$(document).ready(function(){
$('.navbar-burger').click(function(){
$('.inactive').toggleClass('active-nav');
$('.navbar-burger').toggleClass('inactive');
$('.navbar-close').toggleClass('close-navi');
$('.header').toggleClass('border-bg');
})
$('.navbar-close').click(function(){
$('.inactive').removeClass('active-nav');
$('.navbar-burger').removeClass('inactive');
$('.navbar-close').removeClass('close-navi');
$('.header').removeClass('border-bg');
})
})
*{
font-family: 'Open Sans Light', sans-serif;
color: black;
}
body{
margin: 25px 60px;
background-color: #fafafa;
font-size: 16px;
}
.header{
float: right;
transition: 0.4s ease-in-out;
}
.navbar{
font-size: 1.2em;
}
.navbar ul{
list-style: none;
margin: 0px;
padding: 0;
}
.navbar ul li{
display: inline-block;
margin: 0px 15px;
}
.navbar ul li a{
text-decoration: none;
}
.navbar ul li a:hover{
color: #70BCFF;
}
.content{
width: 100%;
display: grid;
grid-template-columns: 50% 50%;
padding: 70px 0px;
cursor: default;
}
.welcome-message h1{
font-size: 5.3em;
margin: 0px;
}
.welcome-message h2{
font-size: 2.15em;
font-weight: 100;
margin: 0px;
line-height: 60px;
color: #707070;
}
.welcome-message h4{
font-size: 1.0625em;
color: #8D8D8D;
margin-left: 4px;
}
.welcome-message p{
font-size: 1.0625em;
color: #8D8D8D;
margin-left: 4px;
}
.expand-bio{
background-color: #fff;
border: 0.3px solid rgba(0, 0, 0, .16);
font-size: 1.0625em;
padding: 20px 30px;
box-shadow: rgba(0, 0, 0, .16) 2px 7px 8px;
border-radius: 15px;
margin-left: 4px;
cursor: pointer;
}
.expand-bio:hover{
box-shadow: rgba(0, 0, 0, .16) 2px 7px 14px;
}
.ava{
display: grid;
grid-template-areas: 100%;
}
.ava img{
width: 70%;
overflow: hidden;
align-self: center;
justify-self: center;
margin: 0px;
}
.navbar-burger,.navbar-close{
display: none;
}
.active a{
color: #70BCFF;
}
/* Responsive Design */
#media only screen and (max-width: 1140px){
body{
font-size: 11px;
}
}
/* iPad && iPad Pro && another tablet */
#media only screen and (max-width: 1024px) and (max-height: 1366px){
body{
font-size: 20px;
}
.content{
grid-template-columns: 100%;
grid-template-rows: 50% 50%;
}
.ava{
grid-area: 1/1;
margin-bottom: 80px;
}
.welcome-message h1, .welcome-message h2, .welcome-message h4, .welcome-message p{
text-align: center;
}
.welcome-message h4{
margin-top: 15px;
}
.expand-bio{
display: block;
margin: 0 auto;
margin-top: 26px;
}
}
/* ================= */
#media only screen and (max-width: 412px){
body{
margin: 25px 10px;
font-size: 20px;
}
.navbar-burger{
position: absolute;
display: block;
right: 20px;
cursor: pointer;
}
.close-navi{
position: absolute;
display: block;
right: 20px;
cursor: pointer;
}
.navbar ul li{
padding-bottom: 15px;
}
.inactive{
display: none;
}
.active-nav{
display: block;
position: absolute;
}
.header{
float: left;
width: 100%;
}
.border-bg{
background-color: #aaa;
}
.content{
padding-top: 0px;
}
}
<!DOCTYPE html>
<head>
<title>Ananda Vijaya</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="main.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://kit.fontawesome.com/b1643406ad.js"></script>
</head>
<body>
<div class="header">
<div id="navbar" class="navbar">
<span class="navbar-burger"><i class="fas fa-bars"></i></span>
<span class="navbar-close"><i class="fas fa-times"></i></span>
<ul class="nav">
<li class="active">Introduction</li>
<span class="inactive">
<li>Finished Project List</li>
<li>Contact Me</li>
</span>
</ul>
</div>
</div>
<div class="content">
<div class="welcome-message">
<h1>Hi There~</h1>
<h2>This is the Place Where You Can Get to<br>Know Me Better</h2>
<h4>Ananda Vijaya || Web Developer</h6>
<p>I'm a Front-end Developer Who Currently a College Student<br>Majoring in Computer Science at Diponegoro University</p>
<button class="expand-bio">My Complete Profile</button>
</div>
<div class="ava">
<img src="ava.png">
</div>
</div>
<div class="footer">
</div>
</body>
</html>
I expect to have all the element (navbar menu) get the gray background color