I'm just starting out with web coding and I don't have much knowledge with css. I think I made some mistakes and I hope I can find a solution here. The issue is when dropdown item
opens, "Add New" slipping sideways. How i can fix this problem? Here is my HTML an CSS code. When i write position: absolute;
dropdown menu is dissappering too. I'm
nav {
background-color: #c1c1c1;
height: 75px;
}
nav .container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
@media (min-width: 768px) {
.container {
width: 750px;
}
}
@media (min-width: 992px) {
.container {
width: 970px;
}
}
@media (min-width: 1200px) {
.container {
width: 1170px;
}
}
nav .logo img {
height: 56px;
width: 56px;
padding-top: 8px;
}
.logo {
width: 30%;
}
.nav-items {
display: flex;
}
.menu {
float: right;
}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.menu ul li {
float: left;
padding-left: 10px;
}
.menu ul li a {
padding: 8px;
color: black;
text-decoration: none;
}
.menu-item-has-children {
position: relative;
display: inline-block;
}
.menu-item-has-children ul {
display: none;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.menu-item-has-children ul li {
float: none;
}
.menu-item-has-children ul li a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.menu-item-has-children:hover ul {
display: block;
}
.menu-item-has-children:hover ul li a:hover {
background-color: #f1f1f1
}
<!DOCTYPE html>
<html>
<head>
<title>NAVBAR</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="nav-first">
<div class="container">
<div class="nav-items">
<div class="logo">
<img src="https://www.postakutun.com/wp-content/uploads/2020/08/cropped-logo-png-120p-2.png" alt="Logo">
</div>
<div class="menu">
<ul class="menu-ul">
<li><a href="#">Home</a></li>
<li><a href="#">Privacy</a></li>
<li><a href="#">Contact</a></li>
<li class="menu-item-has-children"><a href="#">Profile</a>
<ul>
<li><a href="#">My Profile</a></li>
<li><a href="#">Security</a></li>
<li><a href="#">Options</a></li>
</ul>
</li>
<li><a href="#">Add New</a></li>
</ul>
</div>
</div>
</div>
</nav>
</body>
</html>
question from:
https://stackoverflow.com/questions/65850449/navbar-dropdown-issue 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…