Just getting back into coding after a long hiatus - I've dabbled in the past but it's been about 6 years since I've worked with any code.
Currently, I'm working on replicating a website for practice. I have created a nav bar and a dropdown subnav. However, I'm struggling to get the sub nav dropdown to appear directly below the link it is intended for. I will include examples and my code below. Any guidance or corrections are greatly appreciated as I am still learning and would prefer to do things correctly from the start, rather than developing bad habits. I can achieve what I want with the sub nav by using left and right elements with negative px values, but that is not the approach I want to take.
Expected Outcome:
Current Progress: Example 1
I also aim to align the arrow as shown in the example. If anyone knows how to adjust the width properly, please feel free to share your insights.
Here is my HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Arnold Clark | New & Used Cars</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="ac-header">
<a href="#"><img id="ac-logo" src="ac.png" alt="Arnold Clark logo" /></a>
<div id="nav">
<span>Find a car</span>
<div id="nav-Dropdown">
<p>
<div style="font-weight: bold; font-size: 14px;">We sell</div>
</p>
<ul>
<li><a href="#">Used cars</a></li>
<li><a href="#">New cars</a></li>
<li><a href="#">Nearly new cars</a></li>
<li><a href="#">Car finance</a></li>
<li><a href="#">Vans</a></li>
<li><a href="#">Motability</a></li>
</ul>
</div>
</div>
<div id="nav">
<span class="pointer">Find a van</span>
</div>
<div id="nav">
<span class="pointer">Find a dealer</span>
</div>
<div id="nav">
<span class="pointer">Rental</span>
</div>
<div id="nav">
<span class="pointer">Servicing</span>
</div>
<div id="nav">
<span class="pointer">Other</span>
<div id="nav-Dropdown">
<ul>
<div style="font-weight: bold;">
<li>About Arnold Clark</li>
</div>
</ul>
</div>
</div>
</div>
<div id="wrapper">
Content goes in here.
</div>
</body>
</html>
And here is my CSS:
body {
background-color: #fafafa;
font-family: "Gotham A", "Gotham B", "Gotham", "Montserrat", Verdana, sans-serif;
font-size: 14px;
/* Removed the white space on either side of the container */
margin: 0;
padding: 0;
}
#wrapper {
margin-right: auto;
margin-left: auto;
max-width: 1200px;
padding: 15px;
}
#ac-header {
max-width: 100%;
background-color: #2d3737;
height: 63px;
border-bottom: 6px solid #ffde00;
padding-top: 10px;
padding-bottom: 10px;
}
#ac-logo {
object-fit: contain;
width: 285px;
height: 43px;
padding-left: 41px;
margin-top: 10px;
position: absolute;
}
#nav {
position: relative;
display: inline-block;
bottom: 15px;
left: 500px;
top: 15px;
}
#nav > span {
color: #fff;
font-size: 15px;
text-align: center;
display: inline-block;
padding: 8px 8px 8px 8px;
margin-left: 30px;
border-radius: 3px;
cursor: pointer;
}
#nav > span:hover {
color: #ffde00;
background-color: #282e2e;
border-radius: 4px 4px 4px 4px;
-moz-border-radius: 4px 4px 4px 4px;
-webkit-border-radius: 4px 4px 4px 4px;
border: 0px solid #000000;
}
#nav > #nav-Dropdown {
display: none;
position: absolute;
background-color: #fff;
width: 590px;
top: 100px;
padding: 12px 16px;
border-radius: 4px 4px 4px 4px;
-moz-border-radius: 4px 4px 4px 4px;
-webkit-border-radius: 4px 4px 4px 4px;
border: 0px solid #000000;
}
#nav > #nav-Dropdown > ul {
list-style-type: none;
padding: 0;
margin: 0;
font-size: 14px;
}
#nav > #nav-Dropdown > ul > li {
display: inline;
padding: 10px;
right: 10px;
}
#nav > #nav-Dropdown > ul > li > a {
text-decoration: none;
color: #000;
}
#nav:hover #nav-Dropdown {
background-color: #fff;
display: block;
top: 50px;
}