I've been following a tutorial on YouTube that showcases how to create a hoverable dropdown menu using HTML and CSS. The video link can be found below:
Youtube Video Tutorial: https://www.youtube.com/watch?v=9Qrs8p7WgCc
After replicating the code and watching the tutorial multiple times, I noticed discrepancies in the output compared to the creator's version. It seems that there might be differences due to the video being from 2017, particularly noticeable when adding {display:flex} under "nav ul" in our CSS.
Output After Applying {display: flex}
https://i.stack.imgur.com/zQeyp.jpg
Final Result Shown in the Video
https://i.stack.imgur.com/WiINQ.jpg
My Output Post {display:flex}
https://i.stack.imgur.com/MbavT.jpg
My Final Results
https://i.stack.imgur.com/0LcPb.jpg
My index.html Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="menu">
<a href="#" class="brand"><img src="#" alt=""></a>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
</ul>
<li><a href="#">Services</a></li>
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
</ul>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Pages</a></li>
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
<li><a href="#">List 4</a></li>
</ul>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
<section></section>
</body>
</html>
My styles.css
body {
margin: 0;
padding: 0;
}
section {
width: 100%;
height: 100vh;
background: url(bg.jpg);
background-size: cover;
}
.menu {
position: absolute;
width: 100%;
background: rgba(255, 255, 255, .5);
padding: 0 100px;
box-sizing: border-box;
border-bottom: 1px solid rgba(0, 0, 0, .2);
}
.menu img {
float: left;
width: 84px;
}
nav {
position: relative;
float: right;
}
nav ul {
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
list-style: none;
}
nav ul li a {
display: block;
text-transform: uppercase;
font-weight: bold;
padding: 30px 20px;
text-decoration: none;
}
nav ul li ul {
display: block;
border-bottom: 1px solid rgba(0, 0, 0, .5);
min-width: 250px;
position: absolute;
margin-top: 1px;
box-shadow: 0 2px 5px rgba(0, 0, 0, .5);
opacity: 0;
visibility: hidden;
transition: .5s;
transform: translateY(40px);
}
nav ul li:hover ul {
opacity: 1;
visibility: visible;
transform: translateY(0px);
}
nav ul li ul li a {
padding: 10px;
}
The source code provided in the tutorial should ideally yield similar results. Feel free to refer to the short video mentioned above for guidance. Thank you!