I'm new to CSS, and if I'm honest don't really know what I'm doing. For a while now I've been trying to make the child page on the dropdown menu to be at least the same width as the parent page.
After hours of being frustrated that nothing I find on google works, I figured that I should ask someone who actually knows what they're doing. This is the (awful) code:
.menu li > a:after {
color: #fff;
content: ' ▼';
}
.menu li > a:only-child:after {
content: '';
}
#main-nav {
background-color: #6699FF;
height: 40px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
text-align: center;
display: block;
float: left;
width: 100%;
}
#main-nav li {
position: relative;
}
#main-nav ul {
margin: 0 auto;
padding-left: 20px;
padding-right: 20px;
position: relative;
list-style: none;
display: block;
}
#main-nav ul li {
float: left;
display: block;
position: relative;
}
#main-nav ul li a {
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
display: inline;
}
#main-nav a:link, #main-nav a:visited {
color: #FFF;
display: block;
padding: 10px 25px;
height: 20px;
}
/*Sub menus */
#main-nav {
overflow: visible;
}
#main-nav ul {
right: 0;
}
#main-nav ul li ul.sub-menu {
position:absolute;
display:none;
margin: 0;
padding: 0!Important;
float: none;
}
#main-nav ul li:hover ul.sub-menu {
display:block!important;
float: none;
white-space: nowrap;
}
#main-nav ul li ul.sub-menu li {
background: #6699FF;
text-align: left;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
width: auto;
left:0;
}
#main-nav ul li ul.sub-menu li a {
width: auto;
border-radius: 0px;
-moz-border-radius: 0px;
-webkit-border-radius: 0px;
}
This is what it looks like when I hover over the parent 'meep' page:
http://i.imgur.com/rAXvvbP.png?1
I would like it to be the same width, starting from the left so that any excess width due to a long page name would go to the right.
I've tried changing the display type and widths, nothing yet :(
I'd greatly appreciate any help! Thanks in advance
and sorry for the terrible code
JSfiddle: http://jsfiddle.net/q5381Ly5/1/
I only change these two, add width 100%, it will get the whole width of the parent.
here is a demo http://jsfiddle.net/q5381Ly5/4/
#main-nav ul li:hover ul.sub-menu {
display:block!important;
float: none;
white-space: nowrap;
width:100%;
}
#main-nav ul li ul.sub-menu li {
width:100%;
background: #6699FF;
text-align: left;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
left:0;
}
Instead of having width auto to your submenu do change it to 100%
Related
I am trying to set behaviour for menu items in the header like here: http://www.germanamericanconference.org/partners/. There is a bar which slides back and forth when hovering on elements. In my case I can't add another element to my header and such effect should be purely CSS so instead I am using after pseudo-element.
Here, in the example: https://jsfiddle.net/1czmx08y/
As you can see there is a delay when moving between items but even if I decrease transition time, it starts twitching.
How can I avoid such behaviour? I feel like my transition is wrong.
Change all the transitions to 0.15s or 0.18s;
Isn't much better now? i think it would be better and it could be a better choice than using a plugin or more css or any js.
html {
font-family: 'Josefin Slab', 'Comfortaa', sans-serif;
font-size: 1.2em;
background: #eee;
}
ul {
position: relative;
width: 27em;
height: 2em;
margin: 100px auto;
padding: 0;
white-space: nowrap;
}
ul li {
display: inline;
text-align: center;
}
ul li a {
position: relative;
top: 0;
left: 0;
right: 25em;
bottom: 0;
display: inline-block;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: .4em .2em;
color: #09C;
text-decoration: none;
text-shadow: 0 1px 0 white;
/*transition*/
-webkit-transition: width .3s,right .3s;
-moz-transition: width .3s,right .3s;
-o-transition: width .3s,right .3s;
transition: width .19s,right .19s;
}
ul li:nth-child(1) a { width: 2em; }
ul li:nth-child(2) a { width: 4em; }
ul li:nth-child(3) a { width: 4em; }
ul li:nth-child(4) a { width: 12em; }
ul li:nth-child(5) a { width: 5em; }
ul li:last-child a::after {
content: "";
position: absolute;
right: inherit;
bottom: -3px;
width: inherit;
height: 3px;
background: #ccc;
pointer-events: none;
/*transition*/
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .19s ease;
}
ul li:nth-child(1) ~ li:last-child a {
right: 25em;
width: 2em;
}
ul li:nth-child(2):hover ~ li:last-child a {
right: 21em;
width: 4em;
}
ul li:nth-child(3):hover ~ li:last-child a {
right: 17em;
width: 4em;
}
ul li:nth-child(4):hover ~ li:last-child a {
right: 5em;
width: 12em;
}
ul li:nth-child(5):last-child:hover a {
right: 0;
width: 5em;
}
ul li:hover ~ li:last-child a::after,
ul li:last-child:hover a::after { background: #c351fa; }
ul li:last-child a {
min-width: 5em;
max-width: 5em;
}
ul li a:hover,
ul li a:focus {
color: #c351fa;
background-color: rgba(255,255,255,.6);
/*transition*/
-webkit-transition: width .3s,right .3s,background-color .3s;
-moz-transition: width .3s,right .3s,background-color .3s;
-o-transition: width .3s,right .3s,background-color .3s;
transition: width .19s,right .19s,background-color .19s;
}
ul li a:focus { border-bottom: 3px solid #c351fa; }
<ul>
<li> ✿ </li><!--
--><li> Lorem </li><!--
--><li> Ipsum </li><!--
--><li> Consectetur adipisicing </li><!--
--><li> Sit amet </li>
</ul>
I am currently working on a menu bar that expands vertically upwards. When I change the overflow to visible rather than hidden, the menu expands in the correct place, however the whole menu is visible which I do not want to happen. With overflow:hidden; the menu expands but only when you hover over the partially expanded menu above where I would like it to expand. Can anyone help?
.HomeBottomMenu {
-webkit-font-smoothing:antialiased;
text-align: center;
text-align: justify;
position: fixed;
bottom: 6em;
z-index:9999;
}
.HomeBottomMenu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.HomeBottomMenu ul ul {
height: 0px;
}
.HomeBottomMenu ul ul:hover {
height:532px;
-webkit-transition: height 1s ease;
-moz-transition: height 1s ease;
-o-transition: height 1s ease;
-ms-transition: height 1s ease;
transition: height 1s ease;
}
.HomeBottomMenu ul li{
position: relative;
line-height: 21px;
min-width: 220px;
text-align: center;/* Used to be left*/
background: #424242;
}
.HomeBottomMenu ul li a{
display: block;
padding: 8px 8px;
color: #fff;
text-decoration:none;
text-align: left;
font-family: 'BebasNeueRegular', Arial, sans-serif;
font-size: 18px;
font-weight: bold;
}
.HomeBottomMenu ul li a:hover{
color: #fff;
background: #25a0da;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.HomeBottomMenu ul li .dropdown{
background: #f2f2f2;
display: hidden;
position: absolute;
left: -0.01em;
overflow: hidden;
}
.HomeBottomMenu ul li:hover .dropdown{
/* Display the initial dropdown */
display: block;
bottom: 100%;
position: absolute;
background: #939393;
min-height: 50px;
}
.HomeBottomMenu ul li ul.dropdowndropdown {
position: relative;
height:100%;
display:inline-block;
bottom:100%;
}
.HomeBottomMenu ul li ul :hover .dropdowndropdown{
position: relative;
display:inline-block;
}
.HomeBottomMenu ul li ul.dropdowndropdown li{
display: inline-block;
/*Colour of level 1, level 2...*/
background-color: rgba(0, 90, 235, 0.33);
bottom: 100%;
}
.HomeBottomMenu ul li ul.dropdowndropdown li:hover{
position: relative;
}
.HomeBottomMenu ul li ul.dropdowndropdown li a{
color:#fff;
font-size:16px;
padding: 10px 10px;
text-align:center;
}
.HomeBottomMenu ul li ul .dropdowndropdown li a :hover{
color: #fff;
}
Changed the following and it works now:
.HomeBottomMenu ul li .dropdown{
background: #f2f2f2;
position: absolute;
left: -0.01em;
overflow:hidden;
display: none;
}
.HomeBottomMenu ul li:hover .dropdown{
display: block;
bottom: 0%;
position: absolute;
background: #939393;
min-height: 50px;
}
Since a couple of days I'm working on a navigation bar for my website. But I want to center it . Here's my CSS
.nav{
float:right;width:980px
}
.nav ul {
width: 980px;
margin: 0 auto;
padding: 0;
list-style: none;
font-size: 1.5em;
font-weight: 300;
}
.nav li {
float: right;
width: 87px;
text-align: center;
-webkit-transition: border .5s;
-moz-transition: border .5s;
-o-transition: border .5s;
-ms-transition: border .5s;
transition: border .5s;
}
.nav a {
display: block;
width:87px;height: 74px;
}
.no-touch .nav a:hover ,
.nav a:active ,
.nav a:focus {
height: 84px;
}
.nav li span {
display: block;
font-family:"Droid Arabic Kufi";
The float on the nav is unnecessary and the with on the .nav prevents the .nav ul to center.
.nav {
float: right; // Remove this.
width: 100%; // Change this.
}
http://jsfiddle.net/7TBHn/2/
Though in my jsfiddle I use the nav element to be more semantic, but other then that it makes no difference.
Put this in your .nav ul:
margin-left:auto;
margin-right:auto;
This should center it. Hope this helps!
I made my website responsive for tablet and smartphone. I used hover for desktop size, but on mobile size there's hover to. I want to change the hover on the mobile device to a touch without using javascript. I heard something about the no-touch modernizr to change hover to touch event?
nav{
margin-left: 2.7em;
}
nav ul ul {
display: none;
background: #5f6975;
border-radius: 0em;
padding: 0;
position: absolute;
top: 100%;
visibility: hidden;
-webkit-transiton: opacity 0.5s;
-moz-transition: opacity 0.5s;
-ms-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
-transition: opacity 0.5s;
}
nav ul li:hover > ul {
display: block;
opacity: 1;
visibility: visible;
}
nav ul {
background: #333333;
padding: 0 1em;
border-radius: 1em;
list-style: none;
position: relative;
display: inline-block;
}
nav ul li {
float: left;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
nav ul li:hover {
background: #555555;
}
nav ul li:hover a {
color: #ffffff;
}
nav ul li a {
font: 90% helvetica;
display: block;
padding: 1.7em 2em;
color: #ffffff;
text-decoration: none;
}
nav ul ul li {
float: none;
border-top: 0.1em solid #6b727c;
border-bottom: 0.1em solid #575f6a;
position: relative;
}
nav ul ul li a {
padding: 1em 2em;
}
nav ul ul li a:hover {
background: #292F41;
}
#media only screen and (max-width:40em)
What do i need to put here to disable the hover function for mobile and make it a touch?
I would like to adjust the positioning of my drop-down menus on my navigation links. I tried adjusting "nav .folder ul li a " but i couldn't get it to move. I would like to move its position down about 10px.
CSS:
body .main-nav li > a,
body .main-nav li > a:visited {
color: #3b5998;
-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 a:hover {
border-top: solid 4px #b7c3e6;
color: #b7c3e6;
}
.header-alignment-left.header-navigation-split #topNav { position:absolute; right: 0px }
.logo-image #topNav nav li a { padding:4px 15px; line-height: 100% }
#nav a { border-top: 4px solid transparent }
#nav .subnav { margin-top: 4 }
#nav a { border-right:0px solid #3b5998; height: 20px }
#nav li:last-child a { border-right: 0 }
#topNav nav .folder ul li a {
-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 }
#header #topNav nav .folder ul li {
padding: 0 24px 12px;
position: relative; }
#header { margin-top: 20px !important }
#topNav { margin-top: 40px }
#nav .subnav ul { padding-bottom: 15px !important }
#nav .subnav ul { padding-top: 15px !important }
The #topNav nav .folder .subnav div has an absolute top of 100%. If you change that to a px value (say 45px) you can move it.
#topNav nav .folder .subnav {
position: absolute;
top: 45px;
left: 0px;
background: #ffffff;
height: 0;
overflow: hidden;
opacity: 1;
z-index: 999;
}
EDIT: Ended up leaving the above below and adding
#topNav nav li.folder {
height: 32px;
}
Try to add margin-top: 10px; to nav .folder ul
add margin-top: 10px; to #topNav nav .folder ul