When using my css dropdown menu only the text of the dropdown is active which makes it more difficult to select rather than the area which would be easier (especially with mobile devices).
CSS is:
#topMenu ul {
text-align: center;
display: inline;
margin: 0;
padding: 15px 20px 17px 20px;
list-style: none;
}
#topMenu ul li {
font: bold 12px sans-serif;
text-transform:uppercase;
color:#666;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 10px 40px;
background: #EEE;
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;
}
#topMenu ul li:hover {
background: #EEE;
color: #000;
}
#topMenu ul li ul {
z-index: 5000;
padding: 0;
position: absolute;
top: 38px;
left: 0;
width: 150px;
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;
}
#topMenu ul li ul li {
background: #EEE;
display: block;
color: #000;
border:solid 1px #999999;
}
#topMenu ul li ul li:hover { background: #EEE; }
#topMenu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
Code may be a bit cumbersome.
Thanks
You can add display:block; to your anchor tag CSS to make it fill the li.
CSS:
#topMenu ul li ul a {
display: block;
}
HTML:
<ul id="topMenu">
<li>
<ul>
<li>
Link Text
</li>
<!-- more submenu items -->
</ul>
</li>
<!-- more topMenu items -->
</ul>
Try this <---> instead of use padding:10px 40px to determine the height use this:
line-height:30px <---- it replaces the padding top and bottom (20px) and add 10px of the font.
Then your CSS could be:
#topMenu ul li {
font: bold 12px sans-serif;
text-transform:uppercase;
color:#666;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 0px 40px;
line-height:30px;
background: #EEE;
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;
}
If you have a tags inside the li then make it block and the same line-height:
#topmenu ul li a {
display:block;
line-height:30px;
height:30px;
}
Related
So, I have a simple NAV that I came up with, and I'm trying to add a burger icon that will only show up when the screen is small.
Currently, my burger is just the word Menu, but I'd like to have this hidden by default. However, my code is overridden by a display:inline, that is earlier in the code. even if I add !Important.
Any one have any ideas as to how I can hide the menu element?
JSFIDDLE https://jsfiddle.net/Lwwgpx9k/
My code is below.
.html
<div class="nav">
<ul>
<li class="hidden">Menu</li>
<li class="home"><a class="active" href="#">Home</a></li>
<li class="gallery">Gallery</li>
<li class="tutorials">Tutorials</li>
<li class="about">About</li>
</ul>
</div>
.css
body {
background: #333;
}
.nav ul {
color: #e6e9e9;
position: fixed;
top: 60px;
padding-left: 5%;
text-align: center;
margin: 0;
}
.nav ul li {
line-height: 35px;
float: left;
width: 120px;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 0px 10px;
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;
}
.nav ul li:hover {
background: #6A1B9A;
color: #e6e9e9;
}
.nav ul li ul {
padding: 0;
position: absolute;
top: 35px;
left: 0;
text-align: left;
display: none;
opacity: 0;
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 ul li {
width: 200px;
background: #555;
display: block;
color: #e6e9e9;
}
.nav ul li ul li:hover {
background: #6A1B9A;
}
.nav ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
transition-delay: 2s;
-webkit-transition-delay: 2s;
/* Safari */
}
.nav a {
font-size: 1.4em;
text-decoration: none;
color: #e6e9e9;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #6A1B9A;
color: #e6e9e9;
}
.nav a.active {
background-color: #6A1B9A;
color: #e6e9e9;
cursor: default;
}
.nav ul {
color: #e6e9e9;
position: fixed;
top: 60px;
padding-left: 5%;
text-align: center;
margin: 0;
}
.nav ul li {
line-height: 35px;
float: left;
width: 120px;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 0px 10px;
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;
}
.nav ul li:hover {
background: #6A1B9A;
color: #e6e9e9;
}
.nav ul li ul {
padding: 0;
position: absolute;
top: 35px;
left: 0;
text-align: left;
display: none;
opacity: 0;
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 ul li {
width: 200px;
background: #555;
display: block;
color: #e6e9e9;
}
.nav ul li ul li:hover {
background: #6A1B9A;
}
.nav ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
transition-delay: 2s;
-webkit-transition-delay: 2s;
/* Safari */
}
.nav a {
font-size: 1.4em;
text-decoration: none;
color: #e6e9e9;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #6A1B9A;
color: #e6e9e9;
}
.nav a.active {
background-color: #6A1B9A;
color: #e6e9e9;
cursor: default;
}
.hidden {
display: none; !important
}
your problem is here
hidden {
display: none; !important<---- this important should be inside ";"
}
it should be
hidden {
display: none !important;
}
The padding around the link for my dropdown menu isn't clickable. When I mouse over the actual text, it changes color and becomes clickable. How can I make the padding clickable? I read that I should style it as an inline-block, but that didn't work. This is also my first post, so correct me for the countless things that I probably did wrong.
CSS:
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: left;
background-position:center;
background-image:url(sun.jpg);
}
a {
display:inline-block;
color: #6FF;
text-decoration: none;
}
a:hover {
color: #FFF;
}
ul {
color:#6FF
text-align: left;
display: inline-block;
margin: 0;
padding: 1px 1px 1px 0;
list-style: none;
}
ul li {
color: purple;
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -10px;
position: relative;
padding: 20px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding:0;
position:absolute;
top: 54px;
left: 0;
width: 150px;
display: none;
opacity: 0;
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;
}
ul li ul li {
background-color:#555;
color:#6FF;
display: block;
}
ul li ul li:hover { background: #555; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
You should put the padding to the link, no the list item because the link is what is clickable.
body {
font-family:'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: left;
background-position:center;
background-image:url(sun.jpg);
}
a {
padding: 20px 20px;
display:inline-block;
color: #6FF;
text-decoration: none;
}
a:hover {
color: #FFF;
}
ul {
color:#6FF text-align: left;
display: inline-block;
margin: 0;
padding: 1px 1px 1px 0;
list-style: none;
}
ul li {
color: purple;
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -10px;
position: relative;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding:0;
position:absolute;
top: 54px;
left: 0;
width: 150px;
display: none;
opacity: 0;
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;
}
ul li ul li {
background-color:#555;
color:#6FF;
display: block;
}
ul li ul li:hover {
background: #555;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
<ul>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
<li>First link
</li>
</ul>
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 want to reduce the size of the drop down menus to the same as the buttons. Adjusting either the padding or margin would move the items out of place and close themselves when I try to hover over it. I'd like to know what is causing this. Here's the Fiddle
Any help would be great.
CSS:
.sort ul {
text-align: left;
display: inline;
margin: 0;
list-style: none;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
float:right;
}
.sort ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #FF5C00 url(http://i1350.photobucket.com/albums/p769/Stonecold_Stone/Games/SoManySales/Joint%20Supplement/alert-overlay_zpsf561d19b.png) repeat-x;
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;
}
.sort ul li:hover {
background: #555;
color: #fff;
}
.sort 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;
}
.sort ul li ul li {
background: #FFDFDF;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
z-index:9999;
}
.sort ul li ul li:hover { background: #666; }
.sort ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
.button, ul{ padding-left: 15px;}
.button {
list-style: none; cursor: pointer;
float: left; margin: 10px 10px;
background-color: #039fd3; color: #fff;
padding: 5px 10px;
font-size: 13px;
border-radius: 3px;
-webkit-transition:background-color 0.3s ease-in;
-moz-transition:background-color 0.3s ease-in;
-o-transition:background-color 0.3s ease-in;
transition:background-color 0.3s ease-in;
}
HTML:
<div class="sort"><ul>
<li>
Sort AXXX
<ul>
<li><a href='#'>SXXXX</a></li>
<li><a href='%#%'>AXXXx</a></li>
</ul>
</li>
<li>Sort BXXX
<ul>
<li><a href='%#%'>CXXXX</a></li>
</ul>
</li>
<li>Sort C
<ul>
<li><a href='%#%'>WSXXXX</a></li>
<li><a href='%#%'>SXXXX</a></li>
</ul>
</li>
</ul></div>
Following the op coding style, in order to adjust the width of the dropdown it is required to set a width value for the list items under .sort div. Also added paddings similar to the ones set to the blue buttons on the left.
.sort ul li{
width:70px;
padding-top:5px;
padding-bottom:5px;
padding-left:5px;
padding-right:5px;
}
Also it is necesary to adjust the top relative position of the sub menu to always be below the the main menu,
.sort ul li ul{
top:100%;
}
To adjust the distance from the top of the menu to be the same as with the buttons, it is possible to tweak the top relative distance of the menu to achieve it.
The ul element containing the buttons is a block element and the list items within it are floated with a margin-top of 10px and padding-top of 5px so a total of 15px from the top. The ul element within div.sort is floated to the right and has a padding-top of 5px so with margin-top 10px (i.e. 15-5) should be aligned with the buttons.
.sort > ul{
margin-top:10px;
}
http://jsfiddle.net/fLSyE/
First is, if you want your buttons and drop down menu to have the same size, just set the width to be the same. Here is an example(from your code):
.sort ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 100px; /* set width of drop down menu to 100px */
-webkit-box-shadow: none;
/* SOME OTHER CODES FOLLOW */
}
.sort ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
width: 100px; /* also set the width of the menus to 100px */
position: relative;
padding: 15px 20px;
}
Hope it helps!
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