Dropdown issue, propably rookie mistake
I am fairly new in coding and I am trying to create a dropdown menu but can't seem to make it work. I have seen similar questions here and read through almost all of them but me beeing new to this I am not able to apply any of those answers to my code, so that's why I believe a more personalised answer would be a good way for me to understand what's up. It's either something I don't understand about dropdowns or a silly typo that I can't find so any help would be appreciated. Especially any help that could make me understand my error.
I would like to avoid using Bootstrap in order to get a better understanding about how things work.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.navcontainer__dropdown-content:hover {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__item {
float: left;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3Vy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dzLmpwZ1wiKTtcbiAgYmFja2dyb3VuZC1zaXplOiBjb3ZlcjtcbiAgYmFja2dyb3VuZC1yZXBlYXQ6IG5vLXJlcGVhdDtcbn1cbiJdfQ== */
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
html css drop-down-menu dropdown
add a comment |
I am fairly new in coding and I am trying to create a dropdown menu but can't seem to make it work. I have seen similar questions here and read through almost all of them but me beeing new to this I am not able to apply any of those answers to my code, so that's why I believe a more personalised answer would be a good way for me to understand what's up. It's either something I don't understand about dropdowns or a silly typo that I can't find so any help would be appreciated. Especially any help that could make me understand my error.
I would like to avoid using Bootstrap in order to get a better understanding about how things work.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.navcontainer__dropdown-content:hover {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__item {
float: left;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtFQUMxQixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSwwQkFBMEI7RUFDMUIsYUFBYTtFQUNiLGNBQWM7RUFDZCxtQkFBbUI7Q0FDcEI7O0FBRUQ7RUFDRSxhQUFhO0VBQ2IsYUFBYTtFQUNiLG1CQUFtQjtFQUNuQixVQUFVO0VBQ1YsUUFBUTtDQUNUOztBQUVEO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLGNBQWM7RUFDZCxtQkFBbUI7R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ICBvdmVyZmxvdzogaGlkZGVuO1xuICBiYWNrZ3JvdW5kLWNvbG9yOiAjMWExYTFhO1xuICBtYXgtd2lkdGg6IDk1JTtcbiAgbWFyZ2luOiBhdXRvO1xufVxuXG4ubmF2Y29udGFpbmVyX19pdGVtIHtcbiAgZmxvYXQ6IGxlZnQ7XG59XG5cbi5uYXZjb250YWluZXJfX2xpbmsge1xuICBkaXNwbGF5OiBibG9jaztcbiAgcGFkZGluZzogOHB4O1xuICBjb2xvcjogI2YyZjJmMjtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBwYWRkaW5nOiA5cHggMTNweDtcbiAgdGV4dC1kZWNvcmF0aW9uOiBub25lO1xufVxuXG4ubmF2Y29udGFpbmVyX19saW5rOmhvdmVyIHtcbiAgYmFja2dyb3VuZC1jb2xvcjogIzRkNGQ0ZDtcbn1cblxuLndyYXBwZXIge1xuICBtYXJnaW46IGF1dG87XG4gIG1heC13aWR0aDogOTUlO1xuICBib3gtc2hhZG93OiAwcHggMHB4IDIwcHggMCByZ2JhKDAsIDAsIDAsIDAuMik7XG59XG5cbmJvZHkge1xuICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoXCIvc3JjL2ltYWdlcy9uZXdzLmpwZ1wiKTtcbiAgYmFja2dyb3VuZC1zaXplOiBjb3ZlcjtcbiAgYmFja2dyb3VuZC1yZXBlYXQ6IG5vLXJlcGVhdDtcbn1cbiJdfQ== */
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
html css drop-down-menu dropdown
1
take a look at this w3schools.com/howto/…
– J.vee
Nov 14 '18 at 12:55
Your selector.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content
will never match anything - because.navcontainer__dropdown__dropdown-content
is not a descendant of.navcontainer__dropdown
, but the “space” between those two selectors is the descendant combinator. To select the immediately following sibling of the hovered element, you would need to use the adjacent sibling combinator instead. developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/…
– misorude
Nov 14 '18 at 13:03
I agree wth @J.vee. To be more specific you can see the explanation from this link
– Rüzgar
Nov 14 '18 at 13:03
Will read that very carefully, thank you for your time!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
I am fairly new in coding and I am trying to create a dropdown menu but can't seem to make it work. I have seen similar questions here and read through almost all of them but me beeing new to this I am not able to apply any of those answers to my code, so that's why I believe a more personalised answer would be a good way for me to understand what's up. It's either something I don't understand about dropdowns or a silly typo that I can't find so any help would be appreciated. Especially any help that could make me understand my error.
I would like to avoid using Bootstrap in order to get a better understanding about how things work.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.navcontainer__dropdown-content:hover {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__item {
float: left;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtFQUMxQixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSwwQkFBMEI7RUFDMUIsYUFBYTtFQUNiLGNBQWM7RUFDZCxtQkFBbUI7Q0FDcEI7O0FBRUQ7RUFDRSxhQUFhO0VBQ2IsYUFBYTtFQUNiLG1CQUFtQjtFQUNuQixVQUFVO0VBQ1YsUUFBUTtDQUNUOztBQUVEO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLGNBQWM7RUFDZCxtQkFBbUI7RUFDbkIsMEJBQTBCO0VBQzFCLGlCQUFpQjtFQUNqQix3REFBZ0Q7RUFBaEQsZ0RBQWd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tYXgtd2lkdGg6IDk1JTtcbiAgbWFyZ2luOiBhdXRvO1xufVxuXG4ubmF2Y29udGFpbmVyX19pdGVtIHtcbiAgZmxvYXQ6IGxlZnQ7XG59XG5cbi5uYXZjb250YWluZXJfX2xpbmsge1xuICBkaXNwbGF5OiBibG9jaztcbiAgcGFkZGluZzogOHB4O1xuICBjb2xvcjogI2YyZjJmMjtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBwYWRkaW5nOiA5cHggMTNweDtcbiAgdGV4dC1kZWNvcmF0aW9uOiBub25lO1xufVxuXG4ubmF2Y29udGFpbmVyX19saW5rOmhvdmVyIHtcbiAgYmFja2dyb3VuZC1jb2xvcjogIzRkNGQ0ZDtcbn1cblxuLndyYXBwZXIge1xuICBtYXJnaW46IGF1dG87XG4gIG1heC13aWR0aDogOTUlO1xuICBib3gtc2hhZG93OiAwcHggMHB4IDIwcHggMCByZ2JhKDAsIDAsIDAsIDAuMik7XG59XG5cbmJvZHkge1xuICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoXCIvc3JjL2ltYWdlcy9uZXdzLmpwZ1wiKTtcbiAgYmFja2dyb3VuZC1zaXplOiBjb3ZlcjtcbiAgYmFja2dyb3VuZC1yZXBlYXQ6IG5vLXJlcGVhdDtcbn1cbiJdfQ== */
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
html css drop-down-menu dropdown
I am fairly new in coding and I am trying to create a dropdown menu but can't seem to make it work. I have seen similar questions here and read through almost all of them but me beeing new to this I am not able to apply any of those answers to my code, so that's why I believe a more personalised answer would be a good way for me to understand what's up. It's either something I don't understand about dropdowns or a silly typo that I can't find so any help would be appreciated. Especially any help that could make me understand my error.
I would like to avoid using Bootstrap in order to get a better understanding about how things work.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.navcontainer__dropdown-content:hover {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__item {
float: left;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtFQUMxQixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSwwQkFBMEI7RUFDMUIsYUFBYTtFQUNiLGNBQWM7RUFDZCxtQkFBbUI7Q0FDcEI7O0FBRUQ7RUFDRSxhQUFhO0VBQ2IsYUFBYTtFQUNiLG1CQUFtQjtFQUNuQixVQUFVO0VBQ1YsUUFBUTtDQUNUOztBQUVEO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLGNBQWM7RUFDZCxtQkFBbUI7RUFDbkIsMEJBQTBCO0VBQzFCLGlCQUFpQjtFQUNqQix3REFBZ0Q7RUFBaEQsZ0RBQWdEO0VBQ2hELFdBQVc7Q0FDWjs7QUFFRDtFQUNFLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLGVBQWU7RUFDZixtQkFBbUI7RUFDbkIsc0JBQXNCO0VBQ3RCLGVBQWU7RUFDZixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSxlQUFlO0NBQ2hCOztBQUVEO0VBQ0Usc0JBQXNCO0VBQ3RCLFVBQVU7RUFDVixXQUFXO0VBQ1gsaUJBQWlCO0VBQ2pCLDBCQUEwQjtFQUMxQixlQUFlO0VBQ2YsYUFBYTtDQUNkOztBQUVEO0VBQ0UsWUFBWTtDQUNiOztBQUVEO0VBQ0UsZUFBZTtFQUNmLGFBQWE7RUFDYixlQUFlO0VBQ2YsbUJBQW1CO0VBQ25C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F1dG87XG4gIG1heC13aWR0aDogOTUlO1xuICBib3gtc2hhZG93OiAwcHggMHB4IDIwcHggMCByZ2JhKDAsIDAsIDAsIDAuMik7XG59XG5cbmJvZHkge1xuICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoXCIvc3JjL2ltYWdlcy9uZXdzLmpwZ1wiKTtcbiAgYmFja2dyb3VuZC1zaXplOiBjb3ZlcjtcbiAgYmFja2dyb3VuZC1yZXBlYXQ6IG5vLXJlcGVhdDtcbn1cbiJdfQ== */
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.navcontainer__dropdown-content:hover {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__item {
float: left;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtFQUMxQixpQkFBaUI7Q0FDbEI7O0FBRUQ7RUFDRSwwQkFBMEI7RUFDMUIsYUFBYTtFQUNiLGNBQWM7RUFDZCxtQkFBbUI7Q0FDcEI7O0FBRUQ7RUFDRSxhQUFhO0VBQ2IsYUFBYTtFQUNiLG1CQUFtQjtFQUNuQixVQUFVO0VBQ1YsUUFBUTtDQUNUOztBQUVEO0VBQ0UsYUFBYTtFQUNiLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLDBCQUEwQjtDQUMzQjs7QUFFRDtFQUNFLGNBQWM7RUFDZCxtQkFBbUI7RUFDbkIsMEJBQTBCO0VBQzFCLGlCQUFpQjtFQUNqQix3RE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WNvbG9yOiAjMWExYTFhO1xuICBtYXgtd2lkdGg6IDk1JTtcbiAgbWFyZ2luOiBhdXRvO1xufVxuXG4ubmF2Y29udGFpbmVyX19pdGVtIHtcbiAgZmxvYXQ6IGxlZnQ7XG59XG5cbi5uYXZjb250YWluZXJfX2xpbmsge1xuICBkaXNwbGF5OiBibG9jaztcbiAgcGFkZGluZzogOHB4O1xuICBjb2xvcjogI2YyZjJmMjtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBwYWRkaW5nOiA5cHggMTNweDtcbiAgdGV4dC1kZWNvcmF0aW9uOiBub25lO1xufVxuXG4ubmF2Y29udGFpbmVyX19saW5rOmhvdmVyIHtcbiAgYmFja2dyb3VuZC1jb2xvcjogIzRkNGQ0ZDtcbn1cblxuLndyYXBwZXIge1xuICBtYXJnaW46IGF1dG87XG4gIG1heC13aWR0aDogOTUlO1xuICBib3gtc2hhZG93OiAwcHggMHB4IDIwcHggMCByZ2JhKDAsIDAsIDAsIDAuMik7XG59XG5cbmJvZHkge1xuICBiYWNrZ3JvdW5kLWltYWdlOiB1cmwoXCIvc3JjL2ltYWdlcy9uZXdzLmpwZ1wiKTtcbiAgYmFja2dyb3VuZC1zaXplOiBjb3ZlcjtcbiAgYmFja2dyb3VuZC1yZXBlYXQ6IG5vLXJlcGVhdDtcbn1cbiJdfQ== */
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.navcontainer__dropdown-content:hover {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__item {
float: left;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
/*# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW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tcbiAgYmFja2dyb3VuZC1zaXplOiBjb3ZlcjtcbiAgYmFja2dyb3VuZC1yZXBlYXQ6IG5vLXJlcGVhdDtcbn1cbiJdfQ== */
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
html css drop-down-menu dropdown
html css drop-down-menu dropdown
asked Nov 14 '18 at 12:49
Nick KalfasNick Kalfas
31
31
1
take a look at this w3schools.com/howto/…
– J.vee
Nov 14 '18 at 12:55
Your selector.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content
will never match anything - because.navcontainer__dropdown__dropdown-content
is not a descendant of.navcontainer__dropdown
, but the “space” between those two selectors is the descendant combinator. To select the immediately following sibling of the hovered element, you would need to use the adjacent sibling combinator instead. developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/…
– misorude
Nov 14 '18 at 13:03
I agree wth @J.vee. To be more specific you can see the explanation from this link
– Rüzgar
Nov 14 '18 at 13:03
Will read that very carefully, thank you for your time!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
1
take a look at this w3schools.com/howto/…
– J.vee
Nov 14 '18 at 12:55
Your selector.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content
will never match anything - because.navcontainer__dropdown__dropdown-content
is not a descendant of.navcontainer__dropdown
, but the “space” between those two selectors is the descendant combinator. To select the immediately following sibling of the hovered element, you would need to use the adjacent sibling combinator instead. developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/…
– misorude
Nov 14 '18 at 13:03
I agree wth @J.vee. To be more specific you can see the explanation from this link
– Rüzgar
Nov 14 '18 at 13:03
Will read that very carefully, thank you for your time!
– Nick Kalfas
Nov 14 '18 at 13:39
1
1
take a look at this w3schools.com/howto/…
– J.vee
Nov 14 '18 at 12:55
take a look at this w3schools.com/howto/…
– J.vee
Nov 14 '18 at 12:55
Your selector
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content
will never match anything - because .navcontainer__dropdown__dropdown-content
is not a descendant of .navcontainer__dropdown
, but the “space” between those two selectors is the descendant combinator. To select the immediately following sibling of the hovered element, you would need to use the adjacent sibling combinator instead. developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/…– misorude
Nov 14 '18 at 13:03
Your selector
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content
will never match anything - because .navcontainer__dropdown__dropdown-content
is not a descendant of .navcontainer__dropdown
, but the “space” between those two selectors is the descendant combinator. To select the immediately following sibling of the hovered element, you would need to use the adjacent sibling combinator instead. developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/…– misorude
Nov 14 '18 at 13:03
I agree wth @J.vee. To be more specific you can see the explanation from this link
– Rüzgar
Nov 14 '18 at 13:03
I agree wth @J.vee. To be more specific you can see the explanation from this link
– Rüzgar
Nov 14 '18 at 13:03
Will read that very carefully, thank you for your time!
– Nick Kalfas
Nov 14 '18 at 13:39
Will read that very carefully, thank you for your time!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
2 Answers
2
active
oldest
votes
I have added some css please check it.
Your dropdown is child of li
tag so that below css not work for this
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Instead of use this:
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
Also you need to remove overflow for the ul
, other wise you can not show the dropdown.
One more point when you used absolute
position please make sure that it's parent have relative position.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
add a comment |
Looking at your CSS, it looks like a typing error on your part.
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Looks like you have an extra dropdown word in there. try
.navcontainer__dropdown:hover .navcontainer__dropdown-content {
display: block;
}
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300656%2fdropdown-issue-propably-rookie-mistake%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have added some css please check it.
Your dropdown is child of li
tag so that below css not work for this
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Instead of use this:
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
Also you need to remove overflow for the ul
, other wise you can not show the dropdown.
One more point when you used absolute
position please make sure that it's parent have relative position.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
add a comment |
I have added some css please check it.
Your dropdown is child of li
tag so that below css not work for this
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Instead of use this:
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
Also you need to remove overflow for the ul
, other wise you can not show the dropdown.
One more point when you used absolute
position please make sure that it's parent have relative position.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
add a comment |
I have added some css please check it.
Your dropdown is child of li
tag so that below css not work for this
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Instead of use this:
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
Also you need to remove overflow for the ul
, other wise you can not show the dropdown.
One more point when you used absolute
position please make sure that it's parent have relative position.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
I have added some css please check it.
Your dropdown is child of li
tag so that below css not work for this
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Instead of use this:
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
Also you need to remove overflow for the ul
, other wise you can not show the dropdown.
One more point when you used absolute
position please make sure that it's parent have relative position.
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
.flex-container {
margin: auto;
background-color: #ffffff;
min-height: 100%;
}
.header {
background-color: #ffffff;
margin: auto;
height: 100px;
position: relative;
}
.header__logo {
width: 250px;
height: auto;
position: absolute;
top: 10px;
left: 0;
}
.navcontainer {
margin: auto;
background-color: #ffffff;
}
.navcontainer__active {
background-color: #4d4d4d;
}
.navcontainer__dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
min-width: 160px;
-webkit-box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
left: 0; /*New css added */
top: 100%; /*New css added */
}
/*New css added */
.navcontainer__item:hover .navcontainer__dropdown-content {
background-color: #4d4d4d;
display: block;
}
/*New css added */
.navcontainer__dropdown-content a {
display: block;
color: #fff;
text-decoration: none;
padding: 5px 10px;
}
/*New css added */
.navcontainer__dropdown-content a:hover {
color: red;
}
.navcontainer__dropdown-content_dropdown-link {
color: #1a1a1a;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
.navcontainer__navbar {
list-style-type: none;
margin: 0;
padding: 0;
/*overflow: hidden;*/
background-color: #1a1a1a;
max-width: 95%;
margin: auto;
}
.navcontainer__navbar:after{
content:"";
display: table;
clear: both;
}
.navcontainer__item {
float: left;
position: relative;
}
.navcontainer__link {
display: block;
padding: 8px;
color: #f2f2f2;
text-align: center;
padding: 9px 13px;
text-decoration: none;
}
.navcontainer__link:hover {
background-color: #4d4d4d;
}
.wrapper {
margin: auto;
max-width: 95%;
-webkit-box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 20px 0 rgba(0, 0, 0, 0.2);
}
body {
background-image: url("/src/images/news.jpg");
background-size: cover;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>News Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./dist/css/styles.css">
<head>
</head>
<body>
<div class="wrapper">
<header class="header">
<img src="src/images/logo.png" class="header__logo" alt="Logo">
</header>
<div class="navcontainer">
<ul class="navcontainer__navbar">
<li class="navcontainer__item navcontainer__active"><a class="navcontainer__link" href="#home">Home</a></li>
<li class="navcontainer__item">
<a class="navcontainer__link navcontainer__dropdown" href="javascript:void(0)">Categories</a>
<div class="navcontainer__dropdown-content">
<a class="navcontainer__dropdown-link" href="#">Politics</a>
<a class="navcontainer__dropdown-link" href="#">Sports</a>
<a class="navcontainer__dropdown-link" href="#">Finance</a>
</div>
</li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#contact">Contact</a></li>
<li class="navcontainer__item"><a class="navcontainer__link" href="#about">About</a></li>
</ul>
</div>
<div class="flex-container">
Hello World!
</div>
</div>
</body>
</html>
edited Nov 14 '18 at 13:42
answered Nov 14 '18 at 13:00
Minal ChauhanMinal Chauhan
3,1883828
3,1883828
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
add a comment |
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Now it is a nice anwer :)
– J.vee
Nov 14 '18 at 13:21
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
Thank you, that helped a lot, I still don't understand why you did many of the other changes you did though, like not hide the overflow on navbar.
– Nick Kalfas
Nov 14 '18 at 13:34
add a comment |
Looking at your CSS, it looks like a typing error on your part.
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Looks like you have an extra dropdown word in there. try
.navcontainer__dropdown:hover .navcontainer__dropdown-content {
display: block;
}
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
Looking at your CSS, it looks like a typing error on your part.
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Looks like you have an extra dropdown word in there. try
.navcontainer__dropdown:hover .navcontainer__dropdown-content {
display: block;
}
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
Looking at your CSS, it looks like a typing error on your part.
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Looks like you have an extra dropdown word in there. try
.navcontainer__dropdown:hover .navcontainer__dropdown-content {
display: block;
}
Looking at your CSS, it looks like a typing error on your part.
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content {
display: block;
}
Looks like you have an extra dropdown word in there. try
.navcontainer__dropdown:hover .navcontainer__dropdown-content {
display: block;
}
answered Nov 14 '18 at 13:08
Jose GuerraJose Guerra
543
543
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
That was a typo indeed,Thank you!
– Nick Kalfas
Nov 14 '18 at 13:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300656%2fdropdown-issue-propably-rookie-mistake%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
take a look at this w3schools.com/howto/…
– J.vee
Nov 14 '18 at 12:55
Your selector
.navcontainer__dropdown:hover .navcontainer__dropdown__dropdown-content
will never match anything - because.navcontainer__dropdown__dropdown-content
is not a descendant of.navcontainer__dropdown
, but the “space” between those two selectors is the descendant combinator. To select the immediately following sibling of the hovered element, you would need to use the adjacent sibling combinator instead. developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/…– misorude
Nov 14 '18 at 13:03
I agree wth @J.vee. To be more specific you can see the explanation from this link
– Rüzgar
Nov 14 '18 at 13:03
Will read that very carefully, thank you for your time!
– Nick Kalfas
Nov 14 '18 at 13:39