Dropdown position Issue [closed] - html

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm working on navbar dropdown menu and him having some trouble trying to position the dropdown menu with a width 100% but when every I put width to 100% it expands to right but not the left side.
Here the link to a preview of my project working on. Hope someone by can help with the small quick problem having.
Preview Link --> https://brandonpowell.github.io/alegacyleftbehind/
This is what trying to accomplish
HTML
<nav class="navbar-default primary-nav navbar-fixed-top nav-down">
<div class="container-fluid">
<div class="row">
<div class="top-navbar">
<div class="media-icons">
<i class="fa fa-facebook-official" aria-hidden="true"></i>
<i class="fa fa-instagram" aria-hidden="true"></i>
<i class="fa fa-twitter-square" aria-hidden="true"></i>
</div>
</div>
<a href="#"><div class="donate-button">
<p>Donate</p>
</div></a>
<div class="bottom-navbar">
<div class="logo">Logo Here</div>
<div class="nav-menu"><img src="icons/menu.svg"></div>
<ul class="navbar">
<li>Home</li>
<li>Founder's Message</li>
<li>About Us
<ul class="nav-content">
<li>dropdown item 1</li>
<li>dropdown item 2</li>
<li>dropdown item 3</li>
<li>dropdown item 4</li>
<li>dropdown item 5</li>
<li>dropdown item 6</li>
</ul>
</li>
<li>Join Our Team</li>
<li>News & Events</li>
<li>Campus Clubs</li>
<li>Resources</li>
<li>Contact Us</li>
</ul>
</div>
</div>
</div>
</nav>
CSS
body, html {
margin: 0px;
padding: 0px;
box-sizing: border-box; }
nav .top-navbar {
background-color: #212121;
position: absolute;
height: 67px;
width: 100%; }
.donate-button {
position: relative;
float: right;
top: 0px;
z-index: 1; }
.donate-button p {
font-style: Montserrat, sans-serif;
background-color: #961de7;
letter-spacing: 1px;
padding: 21.4px 35px;
margin-bottom: 0px;
font-weight: bold;
text-transform: uppercase;
color: white; }
.bottom-navbar {
background-color: white;
width: 100%;
display: inline-block;
-webkit-box-shadow: 0px 10px 0px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 10px 0px rgba(0, 0, 0, 0.2);
box-shadow: 0px 10px 0px rgba(0, 0, 0, 0.2); }
.nav-menu {
display: none; }
.navbar {
display: table; }
.navbar a:hover {
color: pink; }
.navbar li {
display: table-cell;
list-style-type: none;
padding: 0;
margin: 0;
font-size: 14px;
letter-spacing: 0.5px;
font-weight: bold;
text-transform: uppercase; }
.navbar li a {
text-decoration: none;
color: #212121; }
.nav-content {
position: absolute;
top: 13.3em;
z-index: -1;
padding: 1.3em 0 !important;
overflow: hidden;
width: 100%;
background-color: #a656dc; }
.nav-content a {
color: white;
text-decoration: none; }
.logo {
background-color: #961de7;
color: white;
font-size: 16pt;
float: left;
padding: 39px 6%; }

you need to add a value for 'left' to the nav-content div like this:
.nav-content {
position: absolute;
top: 13.3em;
z-index: -1;
padding: 1.3em 0 !important;
overflow: hidden;
width: 100%;
background-color: #a656dc;
left: 0; /*add this*/
}
and to center the menu add margin:auto to the ul element like this:
.nav-content ul {
margin:auto;
}

Related

How to change current page link colours?

so I've tried a few different things out. But ultimately no success. I'm trying to change the colour of the "Home" link to stay a different colour than the rest when we are specifically on the homepage. So for example, say I'm on the homepage, I specifically want that colour to be orange for the home link, and then when I click on About link, about link changes to orange and the home goes to default white
Html:
<!--Header-->
<header class="header-main">
<!--Navigation menu-->
<nav class="navigation">
<!--Bakingwithwill Logo-->
<img class="logo" src="imgs/bww.png" alt="Bakingwithwill" />
<!--Navigation links-->
<div class="nav-links">
<!--Unordered list of navigation items-->
<ul class="nav-menu">
<li id="active-home" class="nav-items">Home</li>
<li class="nav-items">About</li>
<li class="nav-items">Order</li>
<li class="nav-items">Contact</li>
<li class="nav-items">Cart</li>
</ul>
</div>
<div class="footer-nav">
<!--Footer portion of the side navbar-->
<div class="nav-social">
<!--Navigation of Bakingwithwill social media accounts-->
<ul class="nav-social-list">
<li class="social-icons">
<i class="fab fa-facebook"></i>
</li>
<li class="social-icons">
<i class="fab fa-instagram"></i>
</li>
</ul>
</div>
<p class="copyright">Copyright Bakingwithwill</p>
<!--Copyright-->
</div>
</nav>
<img class="header-banner" src="imgs/bww-home-banner.jpg" alt="Bakingwithwill bread banner"/>
<!--Main image-->
<div class="main">
<!--Contents outside the side navbar representing header page-->
<h2 class="baking-heading">Bakingwithwill</h2>
<h1 class="welcome-heading">Welcome!</h1>
<h2 class="intro-heading">Get a slice of the best bread in<br>
Chatham-Kent!</h2>
</div>
</header>
CSS:
/*Base styles*/
body {
font-family: 'Oswald', sans-serif;
}
h1 {
font-family: 'Satisfy', cursive;
}
/*Home styles*/
header {
width: 100%;
height: 585px;
}
/*Side bar navigation menu*/
.navigation {
height: 100%;
width:160px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #3D3732;
overflow-x: hidden;
padding-top: 20px;
opacity: 90%;
}
.navigation a {
text-decoration: none;
}
.logo {
border-radius: 50%;
height: 70px;
width: 70px;
margin-top: 10px;
margin-left: 45px;
}
#active-home:link, #active-home:visited {
color:#E88F2A !important;
}
.navigation li, p {
text-decoration: none;
color: #FFFFFF;
display: block;
text-align: center;
}
.navigation .nav-items {
padding-right: 30px;
padding-top: 10px;
text-align: center;
}
.navigation .social-icons {
list-style-type: none;
text-align: center;
display: inline;
font-size: 15px;
padding: 5px;
margin-top: 50px;
color: #FFFFFF;
margin-left: 15px;
text-decoration: none;
}
.navigation li:hover {
color: #E88F2A;
}
.navigation p {
font-size: 10px;
text-align: center;
padding: 6px 8px 6px 16px;
}
.main {
margin-left: 160px;
padding: 0px 10px;
}
.footer-nav {
margin-top: 200px;
}
/*Social media icons*/
.navigation i {
text-decoration: none;
color: #FFFFFF;
}
.navigation i:hover {
color: #E88F2A;
}
/*Text overlaying the image*/
.baking-heading {
color: #E88F2A;
font-family: 'Satisfy', cursive;
position: relative;
margin-top: 40px;
padding-left: 50px;
font-size: 50px;
}
.welcome-heading, .intro-heading {
font-family: 'Oswald', sans-serif;
position: relative;
}
.welcome-heading, .baking-heading {
transform: rotate(-13deg);
}
.welcome-heading {
padding-left: 130px;
font-size: 50px;
color: #FFFFFF;
}
.intro-heading {
padding-top: 200px;
font-size: 50px;
text-align: center;
color: #FFFFFF;
}
.header-banner {
/*Image styles*/
margin-top: -40px;
position: absolute;
width: 100%;
height: 585px;
}
So for example, say I'm on the homepage, I specifically want that
colour to be orange for the home link, and then when I click on About
link, about link changes to orange and the home goes to default white
One CSS-only approach is to:
add a class to the <body> element of each page
add classes to each of your links (or to the list-items containing the links)
Home Page:
<body class="home-page">
<ul class="nav-menu">
<li class="nav-items home">Home</li>
<li class="nav-items about">About</li>
<li class="nav-items order">Order</li>
<li class="nav-items contact">Contact</li>
<li class="nav-items cart">Cart</li>
</ul>
About Page:
<body class="about-page">
<ul class="nav-menu">
<li class="nav-items home">Home</li>
<li class="nav-items about">About</li>
<li class="nav-items order">Order</li>
<li class="nav-items contact">Contact</li>
<li class="nav-items cart">Cart</li>
</ul>
Then you can change the color of the relevant link on each page:
.nav-items a {
color: white;
}
.home-page .nav-items.home a,
.about-page .nav-items.about a {
color: orange;
}
You need to add a class to the active link and #id is not recommended for styling. Also, the pseudo classes that you're using is blocking your desired outcome. Try changing :
#active-home:link,
#active-home:visited {
color: #e88f2a !important;
}
to:
.active {
color: #e88f2a !important;
}
Afterwards, place the .active class into your link code for each page. So for home it would be:
<li class="nav-items active">Home</li>
and for your about page:
<a href="#">
<li class="nav-items">Home</li>
</a>
<a href="about.html">
<li class="nav-items active">About</li>
</a>
and so on...

How do I split up a navigation bar into two sections in the same line?

Here's my HTML:
<body>
<nav class="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="fas fa-bars"></i>
</span>
logo
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</nav>
</body>
Here's my CSS:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: "Josefin Sans", sans-serif;
}
.navbar {
font-size: 18px;
padding-bottom: 10px;
}
.main-nav {
list-style-type: none;
display: none;
}
.nav-links,
.logo {
text-decoration: none;
color: black;
}
.main-nav li {
text-align: center;
margin: 15px auto;
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
display: block;
}
And this is the output I'm getting:
I'd like my output to be like this instead (ignore the spacing difference, just my screenshot, but have them split in the center like so):
What's the best way of doing this?
I'm thinking of creating another unorder list and moving it, but I don't know how to do that.
Make use of justify-content: space-between;.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
ul {
list-style-type: none;
}
.nav-links, .logo {
text-decoration: none;
color: #000;
}
.navbar {padding: 20px;}
.navbar, ul {display: flex; flex-direction:row;}
ul li {padding: 0 5px;}
.wrapper {display:flex; justify-content: space-between; width:100%; }
<nav class="navbar">
logo
<div class="wrapper">
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
</ul>
<ul class="ul2">
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</div>
</nav>

Position of drop down menu using only CSS and HTML

Is it possible to position drop down menu under specific button, and not first one by default using only css?
For example, how to but drop down under forth button instead of first one (under INFO instead HOSTEL button)? I know that people usually use <ul> and <li> elements when creating drop downs, but I am interested is it possible to choose a position when using <button> element.
.dropbtn {
background-color: #000000;
color: white;
padding: 8px;
font-size: 9px;
width: 80px;
margin-right: 5px;
font-family: 'Istok Web', sans-serif;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
float: left;
top: 6.7%;
margin-left: 5px;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #95e5c4;
font-family: 'Istok Web', sans-serif;
text-align: center !important;
font-size: 9px;
width: 80px;
box-shadow: 0px 6px 12px 0px rgba(0,0,0,0.2);
z-index: ;
}
.dropdown-content a {
color: black;
padding: 8px 12px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #e6e6e6}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="dropdown">
<button class="dropbtn">HOSTEL</button>
<button class="dropbtn">RESERVATION</button>
<button class="dropbtn">GALLERY</button>
<button class="dropbtn">INFO</button>
<div class="dropdown-content">
EVENTS IN ZG
</div>
<button class="dropbtn">FIND US</button>
</div>
Adding margin-left to the dropdown-content class can be a good choice but may not be the best one. And obviously you have to calculate the value of margin which fits for your actual case. In the example you provided, setting
margin-left to 267px looks fine, I guess.
Edit:
As, OP stated that screen resolutions can be an issue, here's the pure css solution without using any extra margin.
.dropbtn {
background-color: #000000;
color: white;
padding: 8px;
font-size: 9px;
width: 80px;
margin-right: 5px;
font-family: 'Istok Web', sans-serif;
border: none;
cursor: pointer;
}
.dropdown {
display: inline-block;
float: left;
top: 6.7%;
margin-left: 5px;
}
.dropdown-content {
display: none;
background-color: #95e5c4;
font-family: 'Istok Web', sans-serif;
text-align: center !important;
font-size: 9px;
width: 80px;
box-shadow: 0px 6px 12px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content-parent {
display: inline-block;
position: relative;
}
.dropdown-content a {
color: black;
padding: 8px 12px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #e6e6e6
}
.dropdown:hover .dropdown-content {
display: block;
position: absolute;
}
<div class="dropdown">
<button class="dropbtn">HOSTEL</button>
<button class="dropbtn">RESERVATION</button>
<button class="dropbtn">GALLERY</button>
<div class="dropdown-content-parent">
<button class="dropbtn">INFO</button>
<div class="dropdown-content">
EVENTS IN ZG
</div>
</div>
<button class="dropbtn">FIND US</button>
</div>
you can use bootstrap's navbar for it like this:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
</div>
</nav>
<div class="container">
<h3>Navbar With Dropdown</h3>
<p>This example adds a dropdown menu for the "Page 1" button in the navigation bar.</p>
</div>
see it on full screen: https://jsfiddle.net/gmy1Lwfj/

How to display a sub menu to the side of a drop down menu

I have a main menu bar that has a drop down menu and that menu has a sub menu. How do I get the sub drop down menu to display to the left of "drop down 2" link in the first drop down menu? I would also like to align the top of the sub menu to the top of the "drop down 2" link. Right now it's appearing below and to the left of the link.
HTML:
<img src="#" width="100%" height="100px">
<div class="TopMenuBar">
<ul>
<li>Side</li>
<li class="dropdown">menu
<div class="dropdown-menu">
<ul>
<li>drop down 1</li>
<li class="sub-dropdown">drop down 2
<div class="sub-dropdown-menu">
<ul>
<li>sub drop down 1</li>
<li>sub drop down 2</li>
</ul>
</div>
</li>
<li>drop down 3</li>
</ul>
</div>
</li>Bar</li>
</ul>
</div>
<div class="SideMenuBar">
<ul>
<li>Side</li>
<li>Menu</li>
<li>Bar</li>
</ul>
</div>
<h1>h1 Header</h1>
<main>
<h2>h2 Header</h2>
<p>Main paragraph</p>
Main link
<ul>
<li>Main list item</li>
<li>Main list item</li>
<li>Main list item</li>
</ul>
<h2>h2 Header</h2>
<p>Main paragraph</p>
Main link
<ul>
<li>Main list item</li>
<li>Main list item</li>
<li>Main list item</li>
</ul>
</main>
CSS:
.TopMenuBar {
border: none;
background-color: purple;
width: 100%;
margin: 0;
padding: 0;
}
.TopMenuBar>ul {
display: flex;
justify-content: space-between;
margin: 0;
padding: 0;
}
.TopMenuBar>ul, .dropdown-menu>ul, .sub-dropdown-menu>ul{
list-style-type: none;
margin: 0;
padding: 0;
}
.TopMenuBar>li {
display: inline;
}
.TopMenuBar a, .dropdown-menu a, .sub-dropdown-menu a{
color: white;
text-decoration: none;
padding: 20px;
display: block
}
/* Applys to all links under class TopMenuBar on hover */
.TopMenuBar a:hover {
background-color: #b14eb1;
color: black;
}
.dropdown-menu {
}
.dropdown-menu, .sub-dropdown-menu{
display: none;
background-color: purple;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
position: absolute;
z-index: 1;
}
/* Applys to all links under class TopMenuBar */
.dropdown-menu a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-menu{
display: block;
}
.sub-dropdown:hover .sub-dropdown-menu{
display: table;
}
.SideMenuBar {
background-color: orange;
margin-left: 20px;
margin-top: 0;
display: flex;
height: 100vh;
float: left;
}
.SideMenuBar ul {
padding: 0;
margin: 0;
list-style-type: none;
justify-content: space-between;
display: flex;
flex-direction: column;
}
.SideMenuBar li a {
color: white;
text-decoration: none;
padding: 20px;
display: list-item;
}
.SideMenuBar li a:hover {
background-color: #fcbf7e;
color: black;
}
main {
padding-left: 10px;
display: table
}
h1 {
text-align: center;
}
here is a working model at codepen
Add this to the bottom of your stylesheet.
.sub-dropdown{
position: relative;
}
.sub-dropdown-menu{
left: 100%;
top: 0;
}
more here http://codepen.io/hunzaboy/pen/jyRoWB
See This code example, It may help you
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
</style>
</head>
<body>
<div class="container">
<br>
<div class="row">
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li>Some action</li>
<li>Some other action</li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Hover me for more options</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Second level</a></li>
<li class="dropdown-submenu">
Even More..
<ul class="dropdown-menu">
<li>3rd level</li>
<li>3rd level</li>
</ul>
</li>
<li>Second level</li>
<li>Second level</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>

Navigation looks wrong when it's fixed

I want the position of my navigation to be fixed. But when I change the position to "fixed" in nav, it looks very weird.
Here are two examples:
Without fixed position: https://jsfiddle.net/Timowo/3nrvch3c/
<nav>
<ul>
<li class="category">Contact</li>
<li class="category">Work</li>
<li class="category active">Home</li>
<li class="logotext">Logo</li>
</ul>
</nav>
With fixed position: https://jsfiddle.net/Timowo/5aock5k1/
<nav style="position: fixed;">
<ul>
<li class="category">Contact</li>
<li class="category">Work</li>
<li class="category active">Home</li>
<li class="logotext">Logo</li>
</ul>
</nav>
What do I have to change so it's inline but also fixed?
Thanks!
With position:fixed the element will collapse to the width of the widest descendant..in the absence of a defined width.
Just set width:100%
* {
box-sizing: border-box;
}
body {
margin: 0 auto;
background-color: red;
}
nav {
transition: all 0.2s ease-in-out;
position: fixed;
width: 100%;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: transparent;
}
nav ul li.logo {
padding: 14px;
float: left;
}
nav ul li.logotext {
font-family: Futura;
color: white;
font-size: 1.3em;
padding: 28px;
text-shadow: 3px 3px black;
}
nav ul li.category a {
display: block;
color: white;
text-align: center;
padding: 30px 20px;
text-decoration: none;
font-size: 1.2em;
float: right;
font-family: Futura;
text-shadow: 3px 3px black;
}
nav ul li.category:hover a {
background-color: #212121;
}
nav ul li.active a {
background-color: #212121;
}
<nav>
<ul>
<li class="category">Contact
</li>
<li class="category">Work
</li>
<li class="category active">Home
</li>
<li class="logotext">Logo</li>
</ul>
</nav>