hello is it possible that when I hover to the parent item the parent item will also slide up making the drop down menu with parent item above it? here is my code but I cant seem to make it work. here is a visual menu that i want http://imgur.com/om9mvdG (the second image)
.nav ul {
*zoom: 1;
list-style: none;
margin: 0;
padding: 0;
background: #333;
}
.nav ul:before,
.nav ul:after {
content: "";
display: table;
}
.nav ul:after {
clear: both;
}
.nav ul > li {
float: left;
position: relative;
}
.nav a {
display: block;
padding: 10px 20px;
line-height: 1.2em;
color: #fff;
border-left: 1px solid #595959;
}
.nav a:hover {
text-decoration: none;
background: #595959;
}
.nav li ul {
background: #273754;
position: absolute;
left: 0;
bottom: 36px;
z-index: 1;
}
.nav li ul li {
width: 100%;
overflow: hidden;
height: 0;
-webkit-transition: height 200ms ease-in;
-moz-transition: height 200ms ease-in;
-o-transition: height 200ms ease-in;
transition: height 200ms ease-in;
}
.nav li ul a {
border: none;
}
.nav li ul a:hover {
background: rgba(0, 0, 0, 0.2);
}
.nav ul > li:hover ul li {
height: 36px;
}
<ul>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
<li>
Nav Item
<ul>
<li>Subnav
</li>
<li>Subnav
</li>
<li>Subnav
</li>
</ul>
</li>
</ul>
</nav>
Add this css to your already existing code. Is this what you wanted?
http://codepen.io/anon/pen/jbBgdg
li>ul {
display: none;
}
a:hover~ul {
display: block;
}
Related
I want to create a dropdown that right aligns itself to its parent element
Something like this, but where the dropdown's right edge is aligned to its parent's right edge
This link contains the styling I want, the alignment is just not working properly. Any help would be very much appreciated!
a {
text-decoration: none;
}
nav {
font-family: monospace;
}
ul {
background: darkorange;
list-style: none;
margin: 0;
padding-left: 0;
}
li {
color: #fff;
background: darkorange;
display: block;
float: left;
padding: 1rem;
position: relative;
text-decoration: none;
transition-duration: 0.5s;
}
li a {
color: #fff;
}
li:hover {
background: red;
cursor: pointer;
}
ul li ul {
background: orange;
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
left: 0;
display: none;
}
ul li:hover>ul,
ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
ul li ul li {
clear: both;
width: 100%;
}
<nav role="navigation">
<ul>
<li>One</li>
<li>Two
<ul class="dropdown">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li>Three</li>
</ul>
</nav>
Convert left: 0 to right: 0 and change some CSS properties can right-align your dropdown
a {
text-decoration: none;
}
nav {
font-family: monospace;
}
ul {
background: darkorange;
list-style: none;
margin: 0;
padding-left: 0;
}
li {
color: #fff;
background: darkorange;
display: block;
float: left;
padding: 1rem;
position: relative;
text-decoration: none;
transition-duration: 0.5s;
}
li a {
color: #fff;
}
li:hover {
background: red;
cursor: pointer;
}
ul li ul {
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
right: 0;
display: none;
}
ul li:hover>ul,
ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
ul li ul li {
clear: both;
min-width: 3rem;
}
<nav role="navigation">
<ul>
<li>One</li>
<li>Two
<ul class="dropdown">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li>Three</li>
</ul>
</nav>
The Problem:
Look at Offers and the li:
After putting position: absolute
Current vs What I want to achieve
How to make my drop down menu so that when I hover on "Offers" the text doesn't move to the left? I would also like to decrease the width of the li as it is too big for me.
I have tried changing the display: property and putting spaces before and after the word "Offers" in HTML. The spaces worked but I didnt like it because the Offers will just look like having more space than the other options.
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul li ul li {
display: none; /*So li dont show up unless hover */
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
I want to dropdown menu to not move when the li is shown in the Offers. And I would like to decrease the width of black background of the li
That's because the sub menu is taking a place and make its parent li wider.
A possible solution is to set the ul child position: absolute so it will not take a place.
Like this:
.menu ul ul {
position: absolute;
}
Live example:
body {
background: url(https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg) 0 0;
background-size: cover;
}
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
position: relative;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul ul {
position: absolute;
width: 100%;
}
.menu ul li ul li {
display: none;
/*So li dont show up unless hover */
}
.menu ul li ul li a {
padding: 0;
text-align: center;
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
The problem lies with the min-content size of the list items in the drop down, which are larger than the size of the parent list items in the top menu.
e.g. 'packages' renders at 120px whereas 'offers' is 98px.
The simplest solution is to set a max-width for all the list items based on the max-content size of the longest word (not very dynamic though).
Otherwise, use position:absolute to layout the sub menu as in this example:
https://codepen.io/skippingredpanda/pen/xNrxVg
Is simple, use:
.menu li { position: relative; } .menu li ul { position: absolute; top: your horizontal nav height; left: 0;}
And also you have a mistake in code, must be like this:
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>
Link 3
<ul>
<li>SubLink 1</li>
<li>SubLink 2</li>
<li>SubLink 3</li>
<li>SubLink 4</li>
</ul>
</li>
<li>Link 4</li>
</ul>
ul li {position: relative;}
ul li ul {position: absolute; display: none;}
ul li:hover ul {display: block;}
I am making a css navbar dropdown, and am having some issues. I'm not the most experienced person in css, so a little help would be appreciated.
The products text doesn't change color, like on the other ones and you can only click on the text of the products box.
Also the dropdown is not horizontally aligned with the products box.
Here's a link to jsfiddle:
https://jsfiddle.net/epp0zmd6/
Code(HTML):
<div class="navbar">
<ul>
<li class="active">Homepage</li>
<li>Contact Us</li>
<li>Web Learning Platform</li>
<li><a href="#">Products
<ul>
<li>Requirement Extraction & Analysis</li>
<li>Early Deduction Modelling & Analysis</li>
</ul>
</li></a>
</ul>
</div>
Code(CSS):
.navbar ul {
display: inline-table;
vertical-align: middle;
list-style: none;
position: relative;
}
.navbar ul:after {
content: "";
clear: both;
display: block;
}
.navbar ul ul {
display: none;
border-radius: 0;
padding: 0;
position: absolute;
top: 100%;
}
.navbar ul ul li {
float: none;
position: relative;
}
.navbar ul li:hover > ul {
display: block;
}
.navbar ul li {
background-color: #0A6CA3;
display: inline-block;
vertical-align: middle;
font-family: SinkinSans;
font-size: 20px;
padding-top: 27px;
padding-bottom: 21px;
padding-left: 10px;
padding-right: 10px;
color: #FFFFFF;
transition: all 0.8s;
-moz-transition: all 0.8s;
-webkit-transition: all 0.8s;
-o-transition: all 0.8s;
margin-left: -2px;
margin-right: -2px;
float: left;
}
.navbar ul li:hover {
background-color: #FFFFFF;
color: #00A3FF;
}
.navbar ul a {
text-decoration: none;
}
.navbar ul a:visited {
color: #FFFFFF;
}
.navbar ul a:hover {
color: #00A3FF;
}
.navbar ul .active {
background-color: #FFFFFF;
color: #00A3FF;
}
the first mistake is, always put anchor tag inside the li tag
and second mistake is for the dropdown use ul > li > a and than, start child ul before closing li and after closing the anchor tag
and for proper clicking i have put padding on anchor tag with display inline block property.
i have updated fiddle i think you want something like this try this, hope the code will help you.
.navbar ul {
display: inline-table;
vertical-align: middle;
list-style: none;
position: relative;
}
.navbar ul:after {
content: "";
clear: both;
display: block;
}
.navbar ul ul {
display: none;
border-radius: 0;
padding: 0;
position: absolute;
top: 100%;
}
.navbar ul li:hover > ul {
display: block;
}
.navbar ul li {
display: inline-block;
margin-left: -2px;
margin-right: -2px;
float: left;
}
.navbar ul li >a{
padding-top: 27px;
padding-bottom: 21px;
padding-left: 10px;
padding-right: 10px;
display:inline-block;
color:#fff;
text-decoration: none;
background-color: #0A6CA3;vertical-align: middle;
font-family: SinkinSans;
font-size: 20px;
transition: all 0.8s;
-moz-transition: all 0.8s;
-webkit-transition: all 0.8s;
-o-transition: all 0.8s;
}
.navbar ul li:hover >a,
.navbar ul li.active >a{
background-color: #FFFFFF;
text-decoration: none;
color: #00A3FF;
}
<div class="navbar">
<ul>
<li class="active">Homepage</li>
<li>Contact Us</li>
<li>Web Learning Platform</li>
<li>Products
<ul>
<li>Requirement Extraction & Analysis</li>
<li>Early Deduction Modelling & Analysis</li>
</ul>
</li>
</ul>
</div>
You have 2 links on your "Products" entry, that's too much:
<li><a href="#">Products
etc.
Just remove one.
Concerning the position of the dropdown: add
.navbar ul li { left: -8px; }
hi i am trying to add a drop down item to my horizontal menu bar. i would like the drop down item to be "Parish council minutes" under "parish council information" like these but in my styles:
(http://www2.psd100.com/wp-content/uploads/2013/03/web-dropdown-menu-bar-psd0306.jpg)
i also intend to add a few more drop down menu item in different locations.
many thank in advance.
my css:
my css:
#cssmenu {
background: #f96e5b;
width: 1404px;
margin-right:auto;
margin-left:auto;
padding:0;
}
#cssmenu ul {
list-style: none;
margin: 0%;
padding: 0%;
line-height: 1;
display: block;
zoom: 1;
width:100%
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0%;
height: 0%;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0%;
margin: 0%;
}
#cssmenu.align-right ul li {
float: right;
}
#cssmenu.align-center ul {
text-align: center;
}
#cssmenu ul li a {
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color .25s;
-o-transition: color .25s;
transition: color .25s;
}
#cssmenu ul li a:hover {
color: #333333;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #ffffff;
opacity: .5;
}
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #333333;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width .25s;
-o-transition: width .25s;
transition: width .25s;
}
#cssmenu ul li.last > a:after,
#cssmenu ul li:last-child > a:after {
display: none;
}
#cssmenu ul li.active a {
color: #333333;
}
#cssmenu ul li.active a:before {
width: 100%;
}
#cssmenu.align-right li.last > a:after,
#cssmenu.align-right li:last-child > a:after {
display: block;
}
#cssmenu.align-right li:first-child a:after {
display: none;
}
#media screen and (max-width: 100%) {
#cssmenu ul li {
float: none;
display: block;
}
#cssmenu ul li a {
width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-bottom: 1px solid #fb998c;
}
#cssmenu ul li.last > a,
#cssmenu ul li:last-child > a {
border: 0;
}
#cssmenu ul li a:after {
display: none;
}
#cssmenu ul li a:before {
display: none;
}
}
#menubar2 {
width:400px;
margin-left:auto;
margin-right:auto;
}
my html:
<div id='cssmenu'>
<ul>
<li class='active'>
<li>Home</li>
<li>Parish Council information</li>
<li>What's on </li>
<li>History</li>
<li>Churches</li>
<li>Newsletter</li>
<li>Village Halls and Social Clubs </li>
<li>Gallery</li>
<div id="menubar2">
<li>Business in Runtons</li>
<li>Contact us</li>
</div>
</ul>
</div>
Put your "flyouts" (lets call it like this cause thats what is is) into your LI's.
Like this:
HTML:
<ul> <!-- this is your horizontal menu bar ul -->
<li>
Some Page
<div class="flyout_container">
<ul>
<li>Some Subpage of Some page
</ul>
</div>
</li>
</ul>
CSS:
ul > li
{
display:block;
position:relative;
height:30px;
}
ul > li .flyout_container
{
position:absolute;
top:30px; /* this is the LI's height*/
left:0;
display:none;
}
ul > li:hover .flyout_container
{
display:block;
}
Normal state you just see the first level and once u hover an LI with a flyout_container in it, it will appear located as you wished on the given screenshot.
So i made a menu with a drop down effect with the css3 transition, but my problem is that you can actually see the text before the background is showing, of course the idea is not to see the text before the background.
I have made a jsfiddle
Html:
<nav>
<ul>
<li>Home</li>
<li>Parrent Link
<ul>
<li>Child Link</li>
<li>Child Link</li>
<li>Parrent Link
<ul>
<li>Child Link</li>
<li>Child Link</li>
<li>Child Link</li>
<li>Child Link</li>
<li>Child Link</li>
</ul>
</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
CSS:
nav {
position: fixed;
top: 0;
width: 100%;
height: 50px;
background: #30a0ff;
z-index: 2;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
}
nav > ul {
position: relative;
margin: 0 auto;
padding: 0;
width: 100%;
list-style: none;
text-align: center;
}
nav > ul > li {
position: relative;
display: inline;
padding: 12px 20px;
line-height: 50px;
font-size: 22px;
color: #fff;
cursor: pointer;
}
nav > ul > li:last-child {
margin: 0 -20px 0 0;
}
nav ul li {
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul li:hover {
background-color: #0f71c4;
}
nav > ul > li > ul {
position: absolute;
top: 50px;
left: 0;
height: 0;
padding: 0;
list-style: none;
line-height: 20px;
font-size: 17px;
background-color: #30a0ff;
overflow: hidden;
}
nav > ul > li:hover > ul {
min-height: 110px;
overflow: visible;
}
nav > ul > li > ul > li:first-child {
padding: 15px 20px 5px 20px;
}
nav > ul > li > ul > li:last-child {
padding: 5px 20px 15px 20px;
}
nav > ul > li > ul > li {
position: relative;
padding: 5px 20px;
min-width: 150px;
text-align: left;
}
nav ul li ul {
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
nav > ul > li > ul > li > ul {
position: absolute;
left: 190px;
top: 0;
padding: 0;
width: 0;
list-style: none;
font-size: 16px;
background-color: #30a0ff;
overflow: hidden;
}
nav > ul > li > ul > li:hover > ul {
min-width: 150px;
}
nav > ul > li > ul > li > ul > li {
position: relative;
padding: 5px 20px;
min-width: 150px;
}
nav > ul > li > ul > li > ul > li:first-child {
padding: 15px 20px 5px 20px;
}
nav > ul > li > ul > li > ul > li:last-child {
padding: 5px 20px 15px 20px;
}
I just added the opacity to the existing css:
js fiddle:
http://jsfiddle.net/r9Dyq/2/
css:
nav > ul > li > ul {
position: absolute;
top: 50px;
left: 0;
height: 0;
padding: 0;
list-style: none;
line-height: 20px;
font-size: 17px;
background-color: #30a0ff;
overflow: hidden;
opacity:0; /*newly added */
}
nav > ul > li:hover > ul {
min-height: 110px;
overflow: visible;
opacity:1; /*newly added */
}
Just don't change the overflow property:
nav > ul > li:hover > ul {
min-height: 110px;
/*overflow: visible; Remove this*/
}
Check this http://jsfiddle.net/r9Dyq/1/