I was trying to write the header of the page with a video as background. The navigation links are available when the screen is above 1200px. But the menu bar is not visible when the screen is made smaller than 1200px. How to fix the invisible menu bar?
This is the html code which includes the video as background and the related navigation links. The menu bars and times icons are also inserted.
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
}
nav img {
width: 140px;
position: relative;
}
.nav-links {
flex: 1;
text-align: right;
}
.nav-links ul li {
list-style: none;
display: inline-block;
padding: 20px 15px;
position: relative;
}
.nav-links ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
.header video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
nav .fa {
display: none;
}
#media (max-width: 1200px) {
.nav-links ul li {
display: block;
padding: 15px 10px;
}
.nav-links {
position: absolute;
background: #fff;
height: 100vh;
width: 200px;
top: 0;
right: -200px;
text-align: left;
z-index: 2;
transition: 1s;
}
nav .fa {
display: block;
cursor: pointer;
margin: 10px;
font-size: 24px;
}
}
<section class="header">
<video src="images/Helicopters9.mp4" muted loop autoplay></video>
<nav>
<img src="images/logo.png" alt="helicopter" />
<div class="nav-links" id="navlinks">
<i class="fa fa-times" onclick="hideMenu()"></i>
<ul>
<li>HOME</li>
<li>FAQ</li>
<li>MEMBER AREA</li>
<li>COMMUNITY GROUP</li>
<li>LATEST PLACES TO FLY</li>
<li>TRANING ONLINE</li>
<li>REVIEW</li>
</ul>
<i class="fa fa-bars" onclick="showMenu()"></i>
</div>
</nav>
</section>
Your menu is visible on smaller than 1200ox screens too. Just change the background-color of link such that white color is visible on it or change color other than white.
On smaller screen a scroll bar is created and your menu aligns to the right-most part of screen
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
}
nav img {
width: 140px;
position: relative;
}
.nav-links {
flex: 1;
text-align: right;
}
.nav-links ul li {
list-style: none;
display: inline-block;
padding: 20px 15px;
position: relative;
}
.nav-links ul li a {
color: red;
text-decoration: none;
font-size: 14px;
}
.header video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
nav .fa {
display: none;
}
#media (max-width: 1200px) {
.nav-links ul li {
display: block;
padding: 15px 10px;
}
.nav-links {
position: absolute;
background: #fff;
height: 100vh;
width: 200px;
top: 0;
right: -200px;
text-align: left;
z-index: 2;
transition: 1s;
}
nav .fa {
display: block;
cursor: pointer;
margin: 10px;
font-size: 24px;
}
}
<section class="header">
<video src="images/Helicopters9.mp4" muted loop autoplay></video>
<nav>
<img src="images/logo.png" alt="helicopter" />
<div class="nav-links" id="navlinks">
<i class="fa fa-times" onclick="hideMenu()"></i>
<ul>
<li>HOME</li>
<li>FAQ</li>
<li>MEMBER AREA</li>
<li>COMMUNITY GROUP</li>
<li>LATEST PLACES TO FLY</li>
<li>TRANING ONLINE</li>
<li>REVIEW</li>
</ul>
<i class="fa fa-bars" onclick="showMenu()"></i>
</div>
</nav>
</section>
Related
I'm new in web development and trying to create a website. I am struggling with my dropdown menu which somehow won't show when I hover on it. I tried changing its position, and when I put it as relative, it shows in an inline-block, but I want it as a block and dropdown. The funny thing is that when I try the code alone then it works but with the rest of my code for the whole website then it doesn't work anymore here is my html :
<!-- Dropdown Menu -->
<div class="main-menu">
<ul>
<li class="dropdown">
DESTINATIONS
<div class="dropdown-content">
CROATIA
FRANCE
SPAIN
SWITZERLAND
</div>
</li>
<li>MAP</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</div>
And here is my css :
.main-menu {
position: absolute;
left: 500px;
top: 100px;
}
.main-menu ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
}
.main-menu li {
float: left;
}
.main-menu li a {
color: #362222;
text-align: center;
display: inline-block;
padding: 14px 16px;
text-decoration: none;
}
.main-menu li a:hover,
.dropdown:hover {
background-color: white;
color: #ceab93;
}
.main-menu li.dropdown {
display: block;
}
.dropdown:hover .dropdown-content a {
display: block;
}
.dropdown-content {
display: block;
position: absolute;
background-color: white;
min-width: 160px;
z-index: 999;
}
.dropdown-content a {
color: #ceab93;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: white;
}
As I explained, the code works on its own but when it is added to my other css code then it won't drop. I have a Logo section just before that and a title section right after, here is the html of it all together:
<!-- Logo -->
<div class="logo-container">
<a href="../html/index.html">
<img src="../images/Logo.jpg" alt="Logo" />
</a>
</div>
<!-- Dropdown Menu -->
<div class="main-menu">
<ul>
<li class="dropdown">
DESTINATIONS
<div class="dropdown-content">
CROATIA
FRANCE
SPAIN
SWITZERLAND
</div>
</li>
<li>MAP</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</div>
<!-- Title -->
<div class="title-container">
<img src="../images/ophelie-ibiza.jpeg" alt="ophelie-ibiza" style="width: 100%" />
<div class="centered">
<h1>Welcome</h1>
</div>
</div>
Here is my css code for those 3 sections :
/* Logo */
.logo-container {
position: relative;
float: none;
width: 400px;
margin: 0;
padding: 0;
}
.logo-container img {
width: 100%;
border-radius: 50%;
}
/* Dropdown Menu */
.main-menu {
position: absolute;
left: 500px;
top: 100px;
}
.main-menu ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
}
.main-menu li {
float: left;
}
.main-menu li a {
color: #362222;
text-align: center;
display: inline-block;
padding: 14px 16px;
text-decoration: none;
}
.main-menu li a:hover,
.dropdown:hover {
background-color: white;
color: #ceab93;
}
.main-menu li.dropdown {
display: block;
}
.dropdown:hover .dropdown-content a {
display: block;
}
.dropdown-content {
display: block;
position: absolute;
background-color: white;
min-width: 160px;
z-index: 999;
}
.dropdown-content a {
color: #ceab93;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: white;
}
/* Title Section */
.title-container {
position: relative;
text-align: center;
}
.title-container img {
margin-top: 0;
margin-bottom: 0;
width: 100%;
height: auto;
display: flex;
}
.centered {
position: absolute;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
}
If anyone has an answer to my problem, please let me know I'm stuck!
the animation dosent work for some reason ( im using normalize dont know if it have an effect + a default start )
i copied the code but it didnt work for me
its second project im rly a real beginner so any advise is welcome
thanks in advance^^
*/ html */
<nav>
<a href="./index.html"
><img src="./eduford_img/logo.png" alt="Uni logo"
/></a>
<div class="nav-links">
<ul>
<li>Home</li>
<li>About</li>
<li>Course</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</nav>
*/ css */
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
nav img {
width: 150px;
}
.nav-links {
flex: 1;
text-align: right;
}
.nav-links ul li {
display: inline-block;
position: relative;
padding: 8px 12px;
}
.nav-links ul li a {
color: #fff;
font-size: 16px;
text-decoration: none;
}
.nav-links ul li a ::after {
content: "";
width: 0%;
height: 2px;
background: var(--primary-400);
display: block;
margin: auto;
transition: var(--transition);
}
.nav-links ul li:hover::after {
width: 100%;
}
Since you put the ::after on the <a> element, you need .nav-links ul li:hover a::after, not .nav-links ul li:hover::after:
*/ html */
<nav>
<a href="./index.html"
><img src="./eduford_img/logo.png" alt="Uni logo"
/></a>
<div class="nav-links">
<ul>
<li>Home</li>
<li>About</li>
<li>Course</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</nav>
*/ css */
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
nav img {
width: 150px;
}
.nav-links {
flex: 1;
text-align: right;
}
.nav-links ul li {
display: inline-block;
position: relative;
padding: 8px 12px;
}
.nav-links ul li a {
color: #fff;
font-size: 16px;
text-decoration: none;
}
.nav-links ul li a::after {
content: "";
width: 0%;
height: 2px;
background: var(--primary-400);
display: block;
margin: auto;
transition: var(--transition);
}
.nav-links ul li:hover a::after {
width: 100%;
}
An example with a few modifications so that it works on this site:
body {
background: black
}
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
nav img {
width: 150px;
}
.nav-links {
flex: 1;
text-align: right;
}
.nav-links ul li {
display: inline-block;
position: relative;
padding: 8px 12px;
}
.nav-links ul li a {
color: #fff;
font-size: 16px;
text-decoration: none;
}
.nav-links ul li a::after {
content: "";
width: 0%;
height: 2px;
background: red;
display: block;
margin: auto;
transition: width 0.5s;
}
.nav-links ul li:hover a::after {
width: 100%;
}
```
<nav>
<a href="./index.html"
><img src="./eduford_img/logo.png" alt="Uni logo"
/></a>
<div class="nav-links">
<ul>
<li>Home</li>
<li>About</li>
<li>Course</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</nav>
When I resize the screen for mobile devices and I hover over links in menu, nothing happens. I don't understand what is wrong. Funny thing is, when I click on the link, the color changes to what it should be when I hover. I tried hover over li and a and both are non functional. Did I miss something?
<nav id="myNav">
<div class="menu-icon" onclick="myFunction()">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo">
<img src="images/logo.png" alt="LOGO">
</div>
<div class="top-nav">
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Work</li>
</ul>
</div>
</nav>
nav {
position: fixed;
width: 100%;
line-height: 60px;
transition: all 1.5s;
}
nav ul {
line-height: 60px;
list-style: none;
overflow: hidden;
color: #fff;
padding: 0;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
.menu li:hover {
background-color: rgba(240, 255, 255, 0.3);
}
nav ul li {
display: inline-block;
padding: 16px 40px;
}
.menu a {
text-decoration: none;
color: #fff;
font-size: 16px;
}
#media only screen and (max-width: 769px) {
nav ul {
max-height: 0px;
background: #000;
}
.show-menu {
max-height: 400px;
}
.menu li:hover {
background-color: azure;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 15px;
text-align: center;
display: block;
}
nav ul li a {
display: block;
font-size: 26px;
}
Problem is when it hits the media size your max list height is 0px. So it will not render Visibly
#media only screen and (max-width: 769px) {
nav ul {
max-height: 0px;
background: #000;
}
Remove the max-height: 0px;
function myFunction() {
}
nav {
position: fixed;
width: 100%;
line-height: 60px;
transition: all 1.5s;
}
nav ul {
line-height: 60px;
list-style: none;
overflow: hidden;
color: #fff;
padding: 0;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
.menu {
background-color: lightgray;
}
.menu li:hover {
background-color: green;
}
nav ul li {
display: inline-block;
padding: 16px 40px;
}
.menu a {
text-decoration: none;
color: #fff;
font-size: 16px;
}
#media only screen and (max-width: 769px) {
nav ul {
background: #000;
}
.show-menu {
max-height: 400px;
}
.menu li:hover {
background-color: red;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 15px;
text-align: center;
display: block;
}
nav ul li a {
display: block;
font-size: 26px;
}
<head>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<nav id="myNav">
<div class="menu-icon" onclick="myFunction()">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo">
<img src="images/logo.png" alt="LOGO">
</div>
<div class="top-nav">
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Work</li>
</ul>
</div>
</nav>
Please can someone help, I've been at this for 2 days and just can't get it right! I'm trying to create a dropdown menu to adhere to my existing navbar. Here's my code below. I have it set that the navbar style changes for smaller windows/mobile and still need to figure that part out wrt the sub menu.. HELP :(
nav {
position: fixed;
width: 100%;
z-index: 10;
}
nav ul {
list-style: none;
background: rgba(0, 0, 0, 0);
overflow: hidden;
color: #000;
padding: 0;
text-align: center;
margin: 0;
transition: 1s;
}
nav ul li {
display: inline-block;
padding-left: 20px;
padding-right: 20px;
padding-top: 5px;
padding-bottom: 5px;
}
nav ul li a {
text-decoration: none;
color: #000;
font-size: 20px;
padding: 5px 5px;
}
nav ul li ul {
display: none;
}
nav ul li:hover ul {
display: block;
position: absolute;
}
nav.black ul {
background: rgba(255, 255, 255, 1);
color: #666;
}
nav.black ul li a {
text-decoration: none;
font-size: 20px;
transition: 1s;
filter: invert(50%);
}
.menu-icon {
width: 100%;
background: #000;
text-align: right;
box-sizing: border-box;
padding: 15px 24px;
cursor: pointer;
color: #00b4ff;
display: none;
}
#media(max-width: 900px) {
.nav-logo {
position: fixed;
top: 0;
margin-top: 16px;
}
nav ul {
max-height: 0px;
background: #000;
}
nav.black ul {
background: #000;
}
.showing {
max-height: 45em;
}
nav ul li {
box-sizing: border-box;
width: 100%;
padding: 24px 0;
text-align: center;
}
.menu-icon {
display: block;
}
}
<div class="nav-wrapper">
<nav>
<div class="menu-icon">
<i class=" fa fa-bars fa-2x"></i>
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Courses
<ul>
<li>PADI Experiences</li>
<li>PADI Basic Courses</li>
<li>PADI Speciality Courses</li>
<li>PADI Pro</li>
</ul>
</li>
<li class="small-nav-logo"><a id="nav-africa" href ="index.html"><img src="img/logo-icon.gif" alt="Home" width="80" height="68"></a></li>
<li>Dives
<ul>
<li>Guided Packages</li>
</ul>
</li>
<li>Nature</li>
<li>Contact</li>
</ul>
</div>
</nav>
</div>
Add this to your css.
nav ul li ul li{
display: block;
text-align: left;
margin: 20px 0px;
}
All you needed to do was target the li inside the li.
I'm having problems where my dropdown menu made with CSS and HTML will force a linebreak and the dropdown menu will glitch out. You can see this problem by running my code.
/* HEADER/NAVBAR */
.main-nav {
text-decoration: none;
list-style-type: none;
display: inline;
text-align: center;
}
li {
display: inline-flex;
margin-left: 70px;
padding-bottom: 0px;
position: inherit;
text-transform: uppercase;
font-family: 'Hind', sans-serif;
font-size: 14px;
}
.nav {
display: inline-block;
padding-bottom: 45px;
margin-top: 65px;
margin-left: 150px;
}
img {
height: 80px;
padding: 20px 0px 0px 20px;
margin: 0px 0px 20px 9%;
display: inline-flex;
float: left;
}
a {
color: #6b6b6b !important;
text-decoration: none;
font-weight: 600;
}
.wrapper {
margin: 0px 9%;
background-color: #f0f0f0;
size: 100vh;
height: 100vh
}
body {
background-color: #f7f7f7 !important;
margin: 0px;
}
.sticky {
background-color: #fff;
}
/* DROP DOWN MENUS */
ul li a:hover {
color: #fff;
;
}
ul li ul.dropdown {
min-width: 10px;
/* Set width of the dropdown */
background: #f2f2f2;
display: none;
position: static;
z-index: 999;
left: 0;
}
ul li:hover ul.dropdown,
ul.dropdown:hover {
display: block;
/* Display the dropdown */
}
ul li ul.dropdown li {
display: block;
}
/* LEGAL STUFF */
.legal {
background-color: #444444;
height: 20vh;
text-align: center;
}
.copy {
padding: 4%;
color: #fff;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<body>
<nav class="sticky">
<div class="row">
<img src="logocopla.Jpg" alt="Copla Logo" class="logo">
<div class="nav">
<ul class="main-nav">
<li>
Home
</li>
<li>
About Us <i class="fa fa-angle-down" aria-hidden="true"></i>
</li>
<li>
Bolivia
</li>
<li>
Products <i class="fa fa-angle-down" `aria-hidden="true"></i>`
<ul class="dropdown">
<li>Laptops</li>
<li>Monitors</li>
<li>Printers</li>
</ul>
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
</nav>
<div class="wrapper">
</div>
<div class="legal">
<p class="copy">. All rights reserved.</p>
</div>
Whenever you hover over "products" the code glitches out and forces a line break. I want to make it so that it doesnt affect the flow of the document. I've already tried to set the float to left and that didn't work.
Thank you!
Instead of position: static; on .dropdown I would go with position:absolute
You will need to iron out some padding and margin of your ul and li tags for proper fit
add position:relative to .dropdown li
See snippet below (I took out some menu items to ensure proper inspection of your product sub-menu where the issue lies)
/* HEADER/NAVBAR */
.main-nav {
text-decoration: none;
list-style-type: none;
display: inline;
text-align: center;
}
li {
display: inline-flex;
margin-left: 70px;
padding-bottom: 0px;
position: inherit;
text-transform: uppercase;
font-family: 'Hind', sans-serif;
font-size: 14px;
}
.nav {
display: inline-block;
padding-bottom: 45px;
margin-top: 65px;
margin-left: 150px;
}
img {
height: 80px;
padding: 20px 0px 0px 20px;
margin: 0px 0px 20px 9%;
display: inline-flex;
float: left;
}
a {
color: #6b6b6b !important;
text-decoration: none;
font-weight: 600;
}
.wrapper {
margin: 0px 9%;
background-color: #f0f0f0;
size: 100vh;
height: 100vh
}
body {
background-color: #f7f7f7 !important;
margin: 0px;
}
.sticky {
background-color: #fff;
}
/* DROP DOWN MENUS */
ul li a:hover {
color: #fff;
;
}
ul li ul.dropdown {
min-width: 10px;
/* Set width of the dropdown */
background: #f2f2f2;
display: none;
position: absolute;
z-index: 999;
left: 0;
padding: 0;
}
.dropdown li {
margin: 0px;
list-style-type: none;
position: relative;
left: 0px;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 40px;
padding-left: 40px;
background: #f2f2f2;
}
.main-nav {
position: relative;
}
ul li:hover ul.dropdown,
ul.dropdown:hover {
display: block;
/* Display the dropdown */
}
ul li ul.dropdown li {
display: block;
}
/* LEGAL STUFF */
.legal {
background-color: #444444;
height: 20vh;
text-align: center;
}
.copy {
padding: 4%;
color: #fff;
}
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Hind:400,600" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="copla.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Copla</title>
</head>
<body>
<nav class="sticky">
<div class="row">
<img src="logocopla.Jpg" alt="Copla Logo" class="logo">
<div class="nav">
<ul class="main-nav">
<li>
Products <i class="fa fa-angle-down" `aria-hidden="true"></i>`
<ul class="dropdown">
<li>Laptops</li>
<li>Monitors</li>
<li>Printers</li>
</ul>
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
</nav>
<div class="wrapper">
</div>
<div class="legal">
<p class="copy">. All rights reserved.</p>
</div>
</body>
</html>