Dropdown menu width by content - html

I have a dropdown menu, which I want change, that the dropdown menu width will be by content. I want to change, that dropdown <li> will be in only one row under main <li> next to each other.
I have it on jsfiddle here, where I have sass which I use. http://jsfiddle.net/hhkrp71f/3/
Here is my solution:
.header__links {
float: right;
margin-top: 40px;
}
.header__links nav ul {
list-style: none;
margin: 0;
padding: 0;
}
.header__links nav ul li {
font-weight: 100;
font-style: italic;
color: red;
float: left;
margin-left: 25px;
}
.header__links nav ul li a {
color: red;
text-decoration: none;
}
.header__links nav ul li a:hover {
color: red;
transition: color 0.7s ease;
}
.header__links nav ul li:hover ul {
visibility: visible;
opacity: 1;
filter: alpha(opacity=100);
}
.header__links nav ul li ul {
visibility: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: 500ms ease;
-moz-transition: 500ms ease;
-o-transition: 500ms ease;
transition: 500ms ease;
position: absolute;
margin: 0;
padding: 20px 0 0;
}
.header__links nav ul li ul li {
margin: 0;
padding: 10px;
background-color: blue;
}
<div class="header__links">
<nav>
<ul>
<li>Test
<ul>
<li>Test Test Test</li>
<li>Test Test</li>
<li>Test Test Test</li>
<li>Test Test</li>
</ul>
</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</nav>
</div>

Add right: 0 to your inner ul.
.header__links {
float: right;
margin-top: 40px;
}
.header__links nav ul {
list-style: none;
margin: 0;
padding: 0;
}
.header__links nav ul li {
font-weight: 100;
font-style: italic;
color: red;
float: left;
margin-left: 25px;
}
.header__links nav ul li a {
color: red;
text-decoration: none;
}
.header__links nav ul li a:hover {
color: red;
transition: color 0.7s ease;
}
.header__links nav ul li:hover ul {
visibility: visible;
opacity: 1;
filter: alpha(opacity=100);
}
.header__links nav ul li ul {
visibility: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: 500ms ease;
-moz-transition: 500ms ease;
-o-transition: 500ms ease;
transition: 500ms ease;
position: absolute;
margin: 0;
padding: 20px 0 0;
right: 0;
}
.header__links nav ul li ul li {
margin: 0;
padding: 10px;
background-color: blue;
}
<div class="header__links">
<nav>
<ul>
<li>Test
<ul>
<li>Test Test Test</li>
<li>Test Test</li>
<li>Test Test Test</li>
<li>Test Test</li>
</ul>
</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</nav>
</div>

Related

Dropdown nav pushing menu down

Currently having a bit of a nightmare with my dropdown menu. When "hovering" over a menu item to view a submenu, the rest of my menu bar is being pushed down.
I have taken the hover out at the moment whilst debugging. Any advice would be great!
https://codepen.io/bradleyr/pen/JjGKZpB
/* CSS: */
.nav-switch {
display: none;
}
.main-menu {
text-align: center;
}
.main-menu ul {
list-style: none;
/* changes from here on */
position: relative;
/* text-align: center; */
}
.main-menu ul li {
display: inline-block;
z-index: 100;
}
.main-menu ul li a {
display: block;
text-transform: uppercase;
font-size: 14px;
color: #fff;
padding: 15px;
margin-left: 20px;
margin-right: 20px;
position: relative;
}
.main-menu ul li img {
height: 7vh;
padding-left: 2vw;
padding-right: 2vw;
}
.main-menu ul li a:after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 1px;
background: #fff;
content: '';
opacity: 0;
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
transition: height 0.3s, opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.main-menu ul li a:hover:after {
height: 3px;
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.main-menu ul li ul {
display: block;
position: relative;
}
.main-menu ul li ul li {
display: block;
/* float: left; */
}
.main-menu ul li ul li a {
font-size: 13px;
width: auto;
min-width: 100px;
/* margin-left: 20px;
margin-right: 20px; */
/* top | right | bottom | left */
}
.main-menu .noLine:hover:after {
opacity: 0;
}
<!-- HTML: -->
<div class="nav-switch">
<i class="fa fa-bars"></i>
</div>
<nav class="main-menu">
<ul>
<li>Who We Are
<li>
What We Do
<ul class="dropdown">
<li>Brand Pop Ups</li>
<li>Weddings</li>
<li>Corporate Events</li>
<li>Festivals</li>
</ul>
</li>
<li>
How We Do It
<ul class="dropdown">
<li>Lighting</li>
<li>Sound</li>
<li>Video</li>
<li>Concept Design</li>
</ul>
</li>
<li>
<img src="/img/logo.svg" class="logoFlashB">
</li>
<!--<li>Venues</li>-->
<li>Case Studies</li>
<li><a href="#">Hire Stock
<li>Contact Us </li>
</ul>
</nav>
Many Thanks,
Brad!!
Example Images...
Broken
How it's supposed to look
Add flex configuration to your .main-menu ul to configure your desire output.
.main-menu ul {
list-style: none;
/* changes from here on */
position: relative;
/* text-align: center; */
display: flex; /* Add this line*/
justify-content: center; /* Add this line */
}
body {
background: black;
}
.nav-switch {
display: none;
}
.main-menu {
text-align: center;
}
.main-menu ul {
list-style: none;
/* changes from here on */
position: relative;
/* text-align: center; */
display: flex; /* Add this line*/
justify-content: center; /* Add this line */
}
.main-menu ul li {
display: inline-block;
z-index: 100;
}
.main-menu ul li a {
display: block;
text-transform: uppercase;
font-size: 14px;
color: #fff;
padding: 15px;
margin-left: 20px;
margin-right: 20px;
position: relative;
}
.main-menu ul li img {
height: 7vh;
padding-left: 2vw;
padding-right: 2vw;
}
.main-menu ul li a:after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 1px;
background: #fff;
content: '';
opacity: 0;
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
transition: height 0.3s, opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.main-menu ul li a:hover:after {
height: 3px;
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
.main-menu ul li ul {
display: block;
position: relative;
}
.main-menu ul li ul li {
display: block;
/* float: left; */
}
.main-menu ul li ul li a {
font-size: 13px;
width: auto;
min-width: 100px;
/* margin-left: 20px;
margin-right: 20px; */
/* top | right | bottom | left */
}
.main-menu .noLine:hover:after {
opacity: 0;
}
<div class="nav-switch">
<i class="fa fa-bars"></i>
</div>
<nav class="main-menu">
<ul>
<li>Who We Are
<li>
What We Do
<ul class="dropdown">
<li>Brand Pop Ups</li>
<li>Weddings</li>
<li>Corporate Events</li>
<li>Festivals</li>
</ul>
</li>
<li>
How We Do It
<ul class="dropdown">
<li>Lighting</li>
<li>Sound</li>
<li>Video</li>
<li>Concept Design</li>
</ul>
</li>
<li>
<img src="/img/logo.svg" class="logoFlashB">
</li>
<!--<li>Venues</li>-->
<li>Case Studies</li>
<li><a href="#">Hire Stock
<li>Contact Us </li>
</ul>
</nav>

parent item drop up with sub menu

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;
}

dropdown menu without borders

I want to do one small and easy dropdown menu, but I dont get it how to do this.
What I exacly mean ? :
And I want to do this thisway: If u click on ENG then its going to index_eng.html, but its not working.
My html:
<nav id="menu2">
<select>
<option href="index.html" value="est">EST</option>
<option href="index_eng.html" value="eng">ENG</option>
</select>
</nav>
My css:
#menu2 {
height: 30px;
overflow: visible;
border-radius: 5px;
background-color: #484848;
color: #FFFFFF;
padding: 5px 5px 0px 5px;
margin: 5px 5px 5px 5px;
font: 8pt verdana, arial, sans-serif;
}
At the moment I have this menu like this, but I want it like this picture above.
Need some clue or solution. Thank you!
Why don't you use anchors?
<nav id="menu2">
<ul>
<li>EST</li>
<li>ENG</li>
</ul>
</nav>
If you do not want to use anchors, you can achieve navigation with jQuery:
$('option').click(function() {
var url = $(this).attr('href');
window.location = url;
});
Try this if the above does not work:
window.location.assign(url);
This is very simple CSS3 drop-down menu:
Demo: http://jsfiddle.net/ahqbbwbm/11/
HTML
<ul>
<li>
EST <span class="arrow-down"></span>
<ul>
<li>EST</li>
<li>ENG</li>
</ul>
</li>
</ul>
CSS
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #2980b9;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
color: #fff;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
min-width: 80px;
background-color: #555;
}
ul li ul li > a {
text-decoration: none;
display: block;
color: #fff;
}
ul li ul li:hover {
background: #666;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li > span {
display: inline-block;
margin: 0 0 -3px 5px;
width: 12px;
height: 12px;
background-image: url('https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-24.png'); /* Change this */
background-size: 12px 12px;
}
http://jsfiddle.net/yf18w6ay/
css
select{
border:0px;
outline:0px;
}
Below is the example for simple pure CSS Drop Down Menu..
HTML
<nav id="primary">
<ul>
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4
<ul>
<li>Deep Menu 1
</li>
<li>Deep Menu 2</li>
</ul>
</li>
<li>Sub Menu 5</li>
</ul>
</li>
</ul>
CSS
#primary
{
margin-top:15px
}
#primary ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
#primary ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
#primary ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
#primary ul li.current-menu-item
{
background:#ddd
}
#primary ul li:hover
{
background:#f6f6f6
}
#primary ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#primary ul ul li
{
float:none;
width:200px
}
#primary ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary ul ul ul
{
top:0;
left:100%
}
#primary ul li:hover > ul
{
display:block
}

Auto width for submenu

I can't get this to work, but in my dropdown menu I just simply can't find a way to make the dropdown menu (for example on account) have it scale with the text.
I tried many things, but only so far a static width is working but that is not what I want
<div class="menu-wrap">
<div class="menu">
<ul class="menu-inner">
<li class="home">Home</li>
<li class="account">Mijn Account
<ul>
<li>Mijn website</li>
<li>Profiel</li>
<li>Persoonlijke gegevens</li>
<li>Voorkeuren</li>
<li>Email instellingen</li>
<li>Log uit</li>
</ul>
</li>
<li class="pages">Mijn pagina's
<ul>
<li>Mijn pagina's</li>
<li>Maak een nieuwe pagina</li>
<li>Verander pagina volgorde</li>
</ul>
</li>
<li class="messages">Mijn berichten
<ul>
<li>Alle privè berichten</li>
<li>Verzonden berichten</li>
<li>Verwijderde berichten</li>
<li>Ongelezen berichten</li>
</ul>
</li>
<li class="forum">Forum
<ul>
<li>Nieuwste berichten</li>
<li>Overzicht</li>
<li>Mijn berichten</li>
<li>Top posters</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="search">Zoeken
<ul>
<li>Zoeken</li>
<li>Vandaag jarig</li>
<li>Online leden</li>
<li>Alle leden</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="online">Online (x)
</ul>
</div>
</div>
and the css code:
.menu-wrap{
position: relative;
background-color: rgba(0,0,0,0.8);
height: 30px;
width: 100%;
text-align: center;
}
.menu {
position: relative;
width: 860px;
margin: 0px auto;
height: 30px;
line-height: 30px;
}
.menu ul {
text-align: left;
display: inline;
margin: 0;
padding: 0;
list-style: none;
}
.menu ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 5px 22px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
background-color: rgba(0,0,0,0.4);
}
.menu ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
.menu ul li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: auto;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
background-color: rgba(0,0,0,0.4)
}
.menu ul li ul li {
color: #fff;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0,0.4);}
.menu ul li:hover ul {
display:inline-block;
opacity: 1;
visibility: visible;
}
All I want is have the sub menus auto scale in width with the text!
You are going to have to add a white-space property to the .menu ul li ul li rule like so:
.menu ul li ul li {
white-space: nowrap;
}

CSS dropdown on hover [duplicate]

This question already has answers here:
CSS drop down menu hover effect
(4 answers)
Closed 8 years ago.
I'm trying to create a drop down navigation bar, this is what I've got.
html
<div class="navBar">
<ul class="navBarStyles navBarWidth navBarMain">
<li class="onSelect">Item1</li>
<li>Item2</li>
<li>Item3</li>
<ul class="navBarExtended">
<li class="borderLeft">ExtraItem</li>
</ul>
<ul class="navBarExtra" id="floatRight">
<li class="i-icon">Dropdown</li>
<ul class="dropdown">
<li>SubItem1<li>
<li>SubItem2<li>
<li>SubItem3<li>
</ul>
</ul>
</ul>
</div>
css
a{
text-decoration: none;
}
.header {
width: 100%;
background-color: #000000;
}
.headerContent{
width: 960px;
margin: 0 auto;
}
.navBar{
font-family: "opensans-regular";
width: 100%;
position: absolute;
line-height: 48px;
background-color: #0088FF; /*0088FF*/
color: #ffffff;
}
.navBarWidth{
width: 400px;
margin: 0 auto;
}
.navBarStyles li{
float: left;
}
.navBarStyles li a{
display: inline-block;
color: #FFFFFF;
font-size: .9em;
text-align: center;
padding-left: 20px;
padding-right: 20px;
vertical-align: top;
letter-spacing: 0;
text-decoration: none;
}
.navBarMain li a:hover{
background-color: #40A5FF; /*#005569 #3D3C3C 12B0CC*/
text-shadow: none;
/* Firefox */
-moz-transition-property: background-color;
-moz-transition-duration: .30s;
-moz-transition-timing-function: ease-out;
-moz-transition-delay: 0s;
/* WebKit */
-webkit-transition-property: background-color;
-webkit-transition-duration: .30s;
-webkit-transition-timing-function: ease-out;
-webkit-transition-delay: 0s;
/* Opera */
-o-transition-property: background-color;
-o-transition-duration: .30s;
-o-transition-timing-function: ease-out;
-o-transition-delay: 0s;
/* Standard */
transition-property: background-color;
transition-duration: .30s;
transition-timing-function: ease-out;
transition-delay: 0s;
}
.navBarExtended li a:hover{
text-decoration: underline;
background: none;
}
/*Class applied to current page element */
.onSelect{
background-color: #40A5FF;
}
/*Navigation Bar Extra - Sytles*/
.navBarExtra li{
float: right;
opacity: .88;
}
.navBarExtra li:hover{
opacity: 1;
background: none;
cursor: pointer;
-moz-transition-property: opacity;
-moz-transition-duration: .30s;
-moz-transition-timing-function: ease-out;
-moz-transition-delay: 0s;
}
.dropdown{
font-family: 'opensans-regular';
font-size: .95em;
}
.navBarExtra ul li{
visibility: hidden;
float: left;
min-width: 150px;
position: absolute;
margin-top: 50px;
left: 0;
z-index: 999;
}
.navBarExtra ul li:hover > ul,
.navBarExtra ul li ul:hover{
visibility: hidden;
}
jsFiddle
but not able to display the sub items under dropdown button. How can I target the dropdown button to display those when user hovers over dropdown button?
To be honest, with all the complicated class names and styles involved in your example, it's hard to work out what needs fixing. I put together a simple example that you can edit to work however you like. Should be pretty self explanatory.
See on fiddle: http://jsfiddle.net/5Uejn/23/
HTML
<ul class="navbar">
<li>page 1</li>
<li>page 2</li>
<li>title 1
<ul>
<li>page 3</li>
<li>page 4</li>
<li>page 5</li>
</ul>
</li>
<li>title 2
<ul>
<li>page 6</li>
<li>page 7</li>
</ul>
</li>
</ul>
CSS
.navbar, .navbar ul
{
font-size:20px;
list-style:none;
z-index:10;
margin:0;
padding:0;
}
.navbar a, .navbar a:link
{
color:black;
text-decoration:none;
}
.navbar li
{
float:left;
background: #666;
width:100px;
}
.navbar li:hover, .navbar a:hover
{
background:#aaa;
color:blue
}
.navbar li ul
{
display:none;
}
.navbar li:hover ul
{
position:absolute;
display:block;
width:100px;
}
.navbar li ul li
{
float:none;
}