Hi guys hope you can help me for some reason my mobile version navigation dropdown menu gets cut down when moving to a real small screen. When the screen is bigger I don't have any issues but when browser is at its smallest it cuts the ("Tours and Daytours") nav in half. I think the problem lies within .dropdown:hover .dropdown-menu class but not sure how to fix it.
function myFunction() {
document.getElementsByClassName("Menu")[0].classList.toggle("responsive");
}
/*hide all list items, except for the first one ("Home").
Show the list item that contains the link to
open and close the topnav (li.icon) */
.Menu li:not(:first-child) {
display: none;
border-bottom: none;
}
.Menu li.icon {
float: right;
display: inline-block;
}
/* The "responsive" class is added to the Menu with JavaScript
when the user clicks on the icon. This class makes the Menu look good
on small screens */
.Menu.responsive {
position: relative;
}
#TA_socialButtonIcon936 {
width: 28px;
height: 28px;
display: inline-flex;
overflow: hidden;
position: relative;
float: none;
}
.Menu {
margin-top: 15px;
width: 54%;
overflow: hidden;
}
.Menu.stick {
margin-top: 10px;
}
.Menu.responsive li.icon {
position: absolute;
right: 0;
top: -4px;
border: none;
}
.Menu.responsive ul li.icon a {
border-bottom: none;
}
.Menu.responsive li {
float: none;
display: inline;
}
.Menu.responsive li a {
display: block;
text-align: left;
background-color: #161616;
border-bottom: solid 1px #FFFFFF;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/*Dropdown arrow for link items*/
.caret {
display: inline-block;
width: 0;
height: 0;
margin-left: 2px;
vertical-align: middle;
border-top: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-menu {
position: absolute;
visibility: hidden;
min-width: 100px;
background-color: #161616;
opacity: 0;
-webkit-transition: opacity 0.4s ease-in-out;
-moz-transition: opacity 0.4s ease-in-out;
transition: opacity 0.4s ease-in-out;
}
/* links inside the dropdown*/
.dropdown-menu a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
border-top: solid 1px #FFFFFF;
border-right: solid 1px #FFFFFF;
margin-top: 0px;
}
.dropdown-menu a:last-child {
border-top: 0;
}
/* Change color of dropdown links on hover */
.dropdown-menu a:hover {
color: #755378;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-menu {
visibility: visible;
right: auto;
left: -151px;
bottom: -47px;
opacity: 1;
}
<div class="Menu">
<!--Nav-menu-->
<!--Social media button-->
<div id="TA_socialButtonIcon936" class="TA_socialButtonIcon">
<ul id="Ug7Rjth" class="TA_links amVFTKsFPp">
<li id="pyCAn7LGV" class="eYF1SLHKaeE">
<a target="_blank" href="https://www.tripadvisor.com/Attraction_Review-g312578-d2284717-Reviews-Felleng_Day_Tours-Johannesburg_Greater_Johannesburg_Gauteng.html">
<img src="https://www.tripadvisor.com/img/cdsi/img2/branding/socialWidget/20x28_white-21690-2.png" alt="media-icon" />
</a>
</li>
</ul>
</div>
<!--End Social media button-->
<ul>
<!--Start Main ul-->
<li>Home
</li>
<li>About Us
</li>
<li class="dropdown">
<a class="DropDown-toggle" data-toggle="dropdown" href="#">Tours <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Tours
</li>
<li>Day Tours
</li>
</ul>
</li>
<li>Contact Us
</li>
<li class="icon">☰
</li>
</ul>
<!--End main ul-->
</div>
<!--End Nav-menu-->
It`s cutted because:
.Menu has {overflow: hidden;} //remove this line
And set width for dropdowns
.dropdown-menu { width: 200px;}
i think you should use media query on your css to set size width
Related
Navigation bar presently drops down, 1st sub menu expands left, 2nd sub menu expands right so that it's on top of the primary menu. Trying to get the 2nd sub menu to continue expanding left, but any tweaks I make don't change it. Tried to get the ul last child to pull right without success, would appreciate any help. Here's the code I've currently got.
HTML:
<li {{#id}}id="{{id}}"{{/id}}
class="wsite-menu-subitem-wrap {{#is_current}}wsite-nav-current{{/is_current}}"
>
<a
{{^nonclickable}}
{{^nav_menu}}
href="{{url}}"
{{/nav_menu}}
{{/nonclickable}}
{{#target}}
target="{{target}}"
{{/target}}
class="wsite-menu-subitem"
>
<span class="wsite-menu-title">
{{{title_html}}}
</span>{{#has_children}}<span class="wsite-menu-arrow">></span>{{/has_children}}
</a>
{{#has_children}}{{> navigation/flyout/list}}{{/has_children}}
<div class="wsite-menu-wrap" style="display:none">
<ul class="wsite-menu">
{{#children}}{{> navigation/flyout/item}}{{/children}}
</ul>
</div>
CSS:
/* Navigation Menu*/
#nav {position: relative;}
#nav ul {
text-align: right;
overflow: hidden;
}
#nav ul li {
list-style: none;
display: inline-block;
}
#nav ul li a {
display: block;
color: #8e8e8e;
padding: 30px 15px;
font-size: 14px;
text-transform: uppercase;
-webkit-transition: all 240ms linear;
-moz-transition: all 240ms linear;
-o-transition: all 240ms linear;
-ms-transition: all 240ms linear;
transition: all 240ms linear;
}
.minimize #nav ul li a {
padding: 15px;
}
#nav > ul li:first-child a {
padding-left: 30px !important;
}
#nav > ul li:last-child a {
padding-right: 0 !important;
}
#nav ul li#active a,
#nav ul li a:hover {
color: #primary;
text-decoration:none;
border: 0;
}
#mobile-nav, #mobile-input, #nav-trigger, #mobile-cart {
display: none;
}
/* Navigation Submenu*/
#wsite-menus {
position: relative;
z-index: 14;
}
#wsite-menus .wsite-menu {
padding: 10px 0;
background: #headerBg;
-webkit-box-shadow: 0px 0px 3px rgba(99, 99, 99, .1);
box-shadow: 0px 0px 3px rgba(99, 99, 99, .1);
}
#wsite-menus > .wsite-menu-wrap > .wsite-menu .wsite-menu-wrap {
position: absolute !important;
top: 0 !important;
margin-top: -10px !important;
}
#wsite-menus .wsite-menu li a {
font-family: 'Roboto', sans-serif;
color: #8e8e8e;
background: transparent !important;
font-size:13px;
text-transform: uppercase;
border: 0;
padding: 10px 20px;
}
#wsite-menus .wsite-menu li a > span {
padding: 0;
}
#wsite-menus .wsite-menu li a:hover {
color: #primary;
}
#wsite-menus .wsite-menu-arrow {
right: 20px;
width: 10px;
overflow: hidden;
}
#wsite-menus .wsite-menu-arrow:before {
display: inline-block;
content: '\25b6';
font-size: 75%;
vertical-align: top;
line-height: 1.5;
}
Try setting the menu's container element to display: flex; and flex-direction: column;. This way child elements will never be one next to the other.
Edit:
Forget the flex.
I'll suppose you need to put your nav to the right (that's why you want submenus to the left), and you need submenus to display one at a time.
Assuming that, I've made an example so you can see it working.
Note: Just check the commented style, other things are just visuals to match your context and to be easy to scan.
* {
margin: 0;
padding: 0;
}
#root {
display: flex;
}
nav {
margin-left: auto;
margin-right: 100px;
background-color: rgb(30, 30, 30);
color: white;
width: 160px;
}
li {
list-style: none;
padding: 4px;
}
li:hover {
background-color: rgb(90, 90, 90);
}
a {
cursor: pointer;
}
/* dropdown box */
.dropdown {
position: relative;
}
/* dropdown button, it's just a span,
you can use whatever you want */
.dropdown .dropdown_btn {}
/* dropdown content default */
.dropdown .dropdown-content {
display: none;
position: absolute;
z-index: 1;
top: 0;
/* "left -100%" gives same result as "right: 100%"*/
left: -100%;
/* keep size to mach the "left -100%" */
min-width: 100%;
background-color: rgb(60, 60, 60);
}
/* while mouse hover, content will display */
.dropdown:hover .dropdown-content {
display: block;
}
<div id="root">
<nav>
<ul>
<li><a>Item 1</a></li>
<li class="dropdown">
<span class="dropdown-btn">Item 2 / Drop A</span>
<ul class="dropdown-content">
<li><a>Drop A Item 1</a></li>
<li><a>Drop A Item 2</a></li>
</ul>
</li>
<li class="dropdown">
<span class="dropdown-btn">Item 3 / Drop B</span>
<ul class="dropdown-content">
<li><a>Drop B Item 1</a></li>
<li><a>Drop B Item 2</a></li>
</ul>
</li>
<li><a>Item 4</a></li>
</ul>
</nav>
</div>
I'm trying to add a bit of spacing between my main menu element and sub menu element.
.dropdown-menu{
margin-top:10px;
}
After adding that the sub-menu is placed where I want it but hovering over "Harry Potter Books" and then trying to mouse from that to the sub-menu, the sub-menu disappears.
I want to be able to hover over the main menu item and be able to mouse over to the sub menu.
Please see this codepen, I am using Bootstrap to implement the base menu styles.
https://codepen.io/anon/pen/ErVEZj?editors=11000#0
Let me know if there are any other pieces of information I can provide.
You should make the .navbar-nav>li>a (the thing you are hovering) take up the full height of the navbar since you want the dropdown menu below the navbar.
To easily do this with your code simply move the 10px of margin top and bottom from the .navbar-nav to padding top and bottom of the .navbar-nav>li>a. Then you can remove that margin-top: 10px from the dropdown menu that creates that anti-hovering gap.
/*Navbar styles*/
.nav-element {
color: white;
}
.navbar-nav {
margin-left: 20px !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
}
.navbar-nav>li>a {
padding-right: 20px !important;
padding-left: 20px !important;
padding-top: 15px !important;
padding-bottom: 15px !important;
color: white !important;
transition: all 0.5s ease;
}
#nav:hover>#nav-details {
display: block;
background-color: lightgrey;
}
/*Divider style for sub-menu */
.divider {
height: 1px;
margin: 9px 20px;
overflow: hidden;
background-color: #e5e5e5;
}
.dropdown-menu {}
.navbar-nav>li {
margin-top: 5px;
}
/*these css blocks contain style for the arrow on the sub-menu*/
.dropdown-menu:after,
.dropdown-menu:before {
bottom: 100%;
left: 80px;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
margin-top: 10px;
}
.dropdown-menu:after {
border-color: rgba(211, 211, 211, 0);
border-bottom-color: #D3D3D3;
border-width: 10px;
margin-left: -10px;
margin-top: 10px;
}
.dropdown-menu:before {
border-color: rgba(0, 0, 0, 0);
border-bottom-color: #;
border-width: 13px;
margin-left: -13px;
margin-top: 10px;
}
/*styles for list elements and hover logic */
li {
color: #fff;
display: block;
float: left;
position: relative;
text-decoration: none;
transition-duration: 0.5s;
}
li span a {
color: #fff;
}
li:hover>a:after {
background: orangered;
}
ul li ul {
visibility: hidden;
opacity: 0;
position: absolute;
transition: all 0.5s ease;
left: 0;
display: none;
}
ul li:hover>ul,
ul li>ul,
ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
ul li:hover>ul,
/*maintain hover state of parent list in sub menus*/
ul li:focus-within>ul,
ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
ul li ul li {
clear: both;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav id="myNavbar" class="navbar navbar-default" role="navigation" style="background-color:royalblue;">
<div class="container">
<div class="navbar-collapse" id="navbarCollapse" style="background-color:royalblue;">
<ul class="nav navbar-nav">
<li id="nav" class="nav-element" aria-haspopup="true">
<a>Harry Potter Books</a>
<ul id="nav-details" aria-label="submenu" class="dropdown-menu sub-menu">
<li>Sorcerer's Stone</li>
<li class="divider"></li>
<li>Chamber of Secrets</li>
<li class="divider"></li>
<li>Deathly Hallows</li>
<li class="divider"></li>
<li>Goblet of Fire</li>
</ul>
</li>
<li class="nav-element" id="ltc-program-nav">
<a>Books Better than Harry Potter</a>
</li>
<li class="nav-element" id="ApplyNowTopLevel">
<a>Another Funny Link</a>
</li>
</ul>
</div>
</div>
</nav>
In the first photo, my cursor is hovering over the slogan in the top right corner. If someone could tell me the adjustments I need to make so that my dropdown menu only comes down when I hover over it, it would be much appreciated.
HTML:
<ul class="dropdown">
<li>Menu</li>
<ul class="dropdownElements">
<li><a href="About.html"/>About</li>
<li><a href="Vintage.html"/>Vintage Products</li>
<li><a href="Antique.html"/>Antique Products</li>
<li><a href="Collectibles.html"/>Collectibles</li>
<li><a href="Contact.html"/>Contact Information</li>
</ul>
</ul>
CSS:
* {
margin: 0px;
padding: 0px;
}
div.header ul.dropdown {
position: absolute;
margin: auto;
list-style: none;
margin-left: 190px;
position: relative;
top: 40px;
}
div.header ul.dropdown li {
background-color: white;
height: 45px;
width: 135px;
line-height: 45px;
border-radius: 5px;
box-shadow: 1px 3px 5px black;
text-align: center
}
ul.dropdownElements li {
list-style: none;
}
div.header ul.dropdown li:hover {
background-color: #C5A06D;
transition: background linear 0.2s;
}
div.header ul ul {
visibility:hidden;
}
div.header ul:hover ul {
visibility:visible;
}
a:link {
text-decoration: none;
color: black;
}
See below. I have removed div.header at a few places because that element isn't in the HTML and stops the CSS from working.
Essential changes: list items of the top level menu positioned relative, submenu positioned absolute.
* {
margin: 0px;
padding: 0px;
}
ul.dropdown {
position: relative;
margin: auto;
list-style: none;
margin-left: 190px;
position: relative;
top: 40px;
}
div.header ul.dropdown li {
background-color: white;
height: 45px;
width: 135px;
line-height: 45px;
border-radius: 5px;
box-shadow: 1px 3px 5px black;
text-align: center
}
ul.dropdownElements {
display: none;
position: absolute;
top: 1em;
left: 0;
}
ul.dropdownElements li {
list-style: none;
}
div.header ul.dropdown li:hover {
background-color: #C5A06D;
transition: background linear 0.2s;
}
ul.dropdown li:hover ul.dropdownElements {
display: inline-block;
}
a:link {
text-decoration: none;
color: black;
}
<ul class="dropdown">
<li>Menu
<ul class="dropdownElements">
<li><a href="About.html" />About</li>
<li><a href="Vintage.html" />Vintage Products</li>
<li><a href="Antique.html" />Antique Products</li>
<li><a href="Collectibles.html" />Collectibles</li>
<li><a href="Contact.html" />Contact Information</li>
</ul>
</li>
</ul>
Here's the code I have problem with my underline hover effect its exppanding extra how to fix it please help me out ************************
HTML
<div class="nav-wrap">
<ul class="group" id="example-one">
<li>Home</li>
<li><a class="dropbtn">Models</a>
<ul class="dropdown-content">
<li></li>
<li>Audi</li>
<li>Bmw</li>
<li>Mercedes</li>
</ul>
</li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul>
</div>
And also i want my dropdown in the middle of his parent And here its*********
CSS
.nav-wrap {
background: white;
width: 100%;
}
#example-one {
text-align: right;
}
#example-one li {
text-align: left;
position: relative;
display: inline-block;
font-family: 'Montserrat', sans-serif;
top:-20px;
}
#example-one a {
color: #000;
font-weight: bold;
font-size: 14px;
padding: 15px 15px;
text-decoration: none;
position: relative;
color: #000;
}
#example-one a:after {
color: #333;
content: '';
position: absolute;
width: 0;
height: 3px;
display: block;
margin-top: 2px;
right: 0;
background: #000;
transition: width all 1s ease;
-webkit-transition: width 1s ease;
}
#example-one a:hover:after {
width: 100%;
left: 0;
background: #000;
}
.dropdown-content {
display: none;
position: absolute;
top: 30px;
left: 0;
background-color:white;
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
#example-one li li {
display: block;
}
#example-one li:hover>ul {
display: block;
}
If I understand your problem correctly, the issue is with the dropdown items not being centered and the dropdown underline being too long. I believe this issue is caused by the padding on the dropdown div.
To resolve this, add some normalised padding to your .dropdown-content class:
.dropdown-content {
padding: 0 20px;
}
let the underline be attached to the text it self not to all the list item so it takes the width of just the text, now it takes the width of the whole cell in the list
I am trying to make a sublevel drop down menu. I have successfully gotten the first menu but the second menu sticks out no matter what when you mouse over the first drop down menu. I want it so that the second level only appears when you mouse over the first level. Any help would be greatly appreciated. The following is my html code:
HTML
<nav>
<ul>
<li><span></span> Home </li>
<li>
<span></span> Jwewlry
<ul>
<li>
<span></span> Rings
<ul>
<li>Silver</li>
<li>Copper</li>
<li>Bronze</li>
</ul>
</li>
<li><span></span> Pendants </li>
<li><span></span> Bracelets </li>
<li><span></span> Necklaces </li>
<li><span></span> Other </li>
</ul>
</li>
<li><span></span> Testimonials </li>
<li><span></span> Latest Offers </li>
<li><span></span> News </li>
<li><span></span> Contact Us </li>
</ul>
</nav>
CSS
nav {
/* Repeating background image */
background: url(texture.png);
width: 210px;
margin: 20px;
}
nav ul {
/* Remove bullet points */
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
/* Any child positioned absolutely will be positioned relative to this */
position: relative;
}
nav ul li ul li ul li {
position: block;
}
nav a {
color: #e8e8e8;
padding: 12px 0px;
/* Fill all available horizontal space */
display: block;
/* Remove underline */
text-decoration: none;
/* New CSS3 animations: apply transition to background property, taking 1s to change it */
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 1s;
-o-transition: background 1s;
font-family: tahoma;
font-size: 13px;
text-transform: uppercase;
padding-left: 20px;
}
nav a:hover {
/* RGBA background for transparancy: last number(0.05) is the transparency */
background: RGBA(255,255,255,0.05);
color: #fff;
}
nav ul li:hover ul {
/* When list item is hovered, display UL nested within. */
display: block;
}
nav ul ul {
/* Remove element from document flow */
position: absolute;
/* Position relative to its parent <li> */
left: 210px;
top: 0;
border-top: 1px solid #e9e9e9;
display: none;
}
nav ul ul li {
width: 200px;
background: #f1f1f1;
border: 1px solid #e9e9e9;
border-top: 0;
}
nav ul ul li a {
color: #a8a8a8;
font-size: 12px;
text-transform: none;
}
nav ul ul li a:hover {
color: #929292;
}
nav span {
width: 12px;
height: 12px;
background: #fff;
display: inline-block;
float: left;
margin-top: 3px;
margin-right: 20px;
position: relative;
transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-webkit-transition: all 0.5s;
}
nav a:hover span {
background: #7d2c41;
transform: rotate(90deg);
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
}
/* Horizontal line */
nav span:before {
content: "";
width: 12px;
height: 2px;
background: #3a3b3b;
position: absolute;
left: 0px;
top: 5px;
}
/* Vertical line */
nav span:after {
content: "";
width: 2px;
height: 12px;
background: #3a3b3b;
position: absolute;
left: 5px;
position: top;
}
Simply change the hover selector to this:
nav ul li:hover > ul
This way only the first child ul element is visible.