I´m building a vertical menu in CSS, but I can´t get the a:hover to work, it´s just doing nothing. I´ve been searching and reviewing the code (I´m new to CSS), but can´t figure it out...if anyone has any suggestions, much appreciated :)
Here´s CSS:
.menu_container{
position: absolute;
float: left;
width: 270px;
margin-top: 220px;
}
.main_menu ul {
padding: 0px;
margin:0px;
list-style-type: none;
}
.main_menu ul li {
padding-right: 25px;
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
letter-spacing:4px;
text-align:right;
line-height:35px;
list-style-type:none;
}
.main_menu ul li a {
text-decoration:none;
color:#999;
}
.main_menu ul li a:hover {
text-decoration:none;
color:#999;
font-weight:bold;
background:url(images/circle_grey.gif) right center no-repeat;
padding-right: 25px;
float:right;
}
.main_menu ul li a.selected {
background: url(images/circle.gif) right center no-repeat;
padding-right: 25px;
float:right;
color: #bc4c9b;
font-weight:bold;
}
HTML:
<div class="menu_container">
<div class="main_menu">
<ul>
<li>HOME</li>
<li><a href="quienes_somos.html" class="selected" >QUIÉNES SOMOS</a></li>
<li>Consultoría</li>
<li>Capacitación</li>
<li>Académico / ARTÍCULOS</li>
<li>Alianzas</li>
<li>Proyectos</li>
<li>Contacto</li>
</ul>
</div>
</div>
The menu was being floated to the left on hover and also on the .selected class and that was what was causing the problem. Here are the fixed classes with the float properties removed:
.main_menu ul li a:hover {
text-decoration:none;
color:#999;
font-weight:bold;
background:url(images/circle_grey.gif) right center no-repeat;
padding-right: 25px;
}
.main_menu ul li a.selected {
background: url(images/circle.gif) right center no-repeat;
padding-right: 25px;
color: #bc4c9b;
font-weight:bold;
}
Related
The menu jump form the left to the right and then back again when I go through the navigation. If I'm in link 1 and click link two, the navigation (not the page) jumps and when I click link 3, same thing.
I can't fiddle it or post the code because it's 4 pages.
Why does it do that and how do I fix it?
EDIT:
HTML
<div id="nav">
<ul>
<li>> om oss</li>
<li>> vad vi gör</li>
<li>> vad är retorik?
<ul>
<li>Presentationsteknik</li>
<li>Retorik & kreativitet</li>
<li>Chef eller ledare?</li>
<li>Retorikens grunder</li>
<li>Memoria</li>
<li>Företagsretorik</li>
<li>Hålla tal</li>
</ul>
</li>
<li>> storytelling</li>
<li>> kontakt</li>
</ul>
</div>
CSS
#nav {
background-color: #8D8084;
}
#nav ul {
margin:0;
list-style-type: none;
padding: 12px;
}
#nav li {
display:inline;
position:relative;
}
#nav ul ul li
{
display:block;
}
#nav ul li a {
text-decoration:none;
color:#fff;
padding-right: 60px;
padding-top: 15px;
padding-bottom: 13px;
padding-left: 50px;
margin: -12px;
background:#8D8084;
font-family: Candara,"Trebuchet MS", Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
text-transform:uppercase;
}
#nav ul ul li a
{
width:170px;
display:block;
margin: 0;
padding-right: 10px;
padding-top: 15px;
padding-bottom: 13px;
padding-left: 20px;
}
#nav ul li.active a {
background-color:#A4999D;
color:#FFFFFF;
}
#nav a:hover {
background-color:#A4999D;
color:#FFF;
}
#nav ul ul {
display: none;
position:absolute;
top:18px;
left:-24px;
}
#nav ul li:hover > ul {
display: block;
}
I think its because your parent div doesn't have a fixed width and height:
#nav {
background-color: #8D8084;
width: 100%;
height: 30px;
}
I have a simple menu and I want to place it in the center of the page using css.
Here's the menu: http://jsfiddle.net/kSV4K/4/
Here's the Codes,
CSS:
ul#menu { margin:0; padding:0; list-style-type:none; }
ul#menu li { position:relative; float:left; border-bottom:4px solid #efefef; margin-right: 0px; padding-right: 0px; padding-bottom: 5px;}
ul#menu .current { border-bottom:4px solid #3d496a;}
ul#menu li:hover { border-bottom:4px solid #3d496a;}
ul#menu li a { padding:2px 2px; text-decoration:none; font:bold 8px Verdana, Georgia, "Times New Roman", Times, serif; color:#68759c;}
ul#menu li a:hover { color:#8895b8; border:none; }
HTML:
<ul id="menu">
<li class="current">Description</li>
<li>Shipping and payment</li>
<li>Returns</li>
<li>Feedback</li>
</ul>
Any suggestions?
Instead of floats, use inline-blocks on the li elements, and then they can be centered applying text-align: center on the ul block.
ul#menu {
margin:0;
padding:0;
list-style-type:none;
text-align: center;
}
ul#menu li {
display: inline-block;
border-bottom:4px solid #efefef;
margin-right: 15px;
padding-right: 20px;
padding-bottom: 5px;
}
See fiddle: http://jsfiddle.net/audetwebdesign/kSV4K/3/
You can also add some width to the menu and apply margin: 0 auto; to center it here is the fiddle http://jsfiddle.net/xtatanx/swT4F/ I also recommend your menu be contained inside a <nav> tag or a <div>.
I hope someone can guide me towards the right direction. I was learning how to use the :before and :after in CSS, so I tried to create a menu navigation, somehow I managed to make it how I wanted with displaying the right shadow image as :before and a :after but now as soon as I roll over my menu it goes up. I tried to put padding and margin with !important but nothing worked.
My second problem is in <li> I have a link <a> but it only changes color of rollover on text. I want to change the color on the whole menu <li> but it doesn't work. My code is in this JsFiddle:
HTML:
<div id="menu">
<ul>
<li class="proxima_bold">Menu1</li>
<li class="proxima_bold">Menu2</li>
<li class="proxima_bold">Menu3</li>
<li class="proxima_bold">Menu4</li>
</ul>
</div>
CSS:
#menu {
text-transform:uppercase;
position:relative;
}
#menu ul{
margin: 0; padding: 0;
float: left;
margin-top:-10px !important;
color:#787878;
}
#menu ul li{
display: inline;
float: left;
padding: 20px 15px 20px 15px;
color:#787878;
background: url(http://www.example.com/p7lpz) no-repeat 0 20px;
}
#menu ul li:hover{
background: url(http://www.example.com/2v4ik) repeat-x;
padding:0;
margin:0;
color: #7fc652 !important;
cursor:pointer;
}
#menu ul li a {
color: #787878;
display:inline-block;
}
#menu ul li a:hover {
color: #7fc652;
}
#menu ul li:hover:after,
#menu ul li:hover:before{
content: "";
position:relative;
top:0;
width:15px;
height:55px;
display:inline-block;
vertical-align:middle;
}
#menu ul li:hover:after{
right: -15px;
background: url(http://www.example.com/9tly4) no-repeat 0 0;
}
#menu ul li:hover:before{
left: -15px;
background: url(http://www.example.com/u969z) no-repeat 0 0;
}
#menu ul li .selected{
float: left;
text-decoration: none;
font-weight:bold;
color: white;
padding: 0 20px 0 20px;
color:#444;
background: url(http://www.example.com/p7lpz) no-repeat 0 0;
}
Please let me know how to fix this.
I HAVE FIXED IT MYSELF. Thank you all for your time.
Is this what you want? I am not sure what the images are supposed to do.
jsfiddle
I´m trying to figure out why the background image on my a:selected class is being cut both bottom and top. I´ve tried assigning height:!important; and min-height; to .main_menu ul li and .main_menu ul li a.selected, but seems like something else is limiting the background image size (17x21px)
I wanted to provide an image, but since I´m new they won´t let me do so :(
The image is a circle and it´s being sliced bottom and top, just as it was to fit into a smaller container
Here´s the code, thanks for any suggestion!
.menu_container{
position: absolute;
float: left;
width: 270px;
margin-top: 220px;
}
.main_menu ul {
padding: 0px;
margin:0px;
list-style-type: none;
}
.main_menu ul li {
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
letter-spacing:4px;
text-align:right;
line-height:35px;
list-style-type:none;
}
.main_menu ul li a {
padding-right: 25px;
text-decoration:none;
color:#999;
}
.main_menu ul li a.selected {
color: #bc4c9b;
font-weight:bold;
background: url(images/circle.gif) right center no-repeat;
height: 35px!important;
}
.main_menu ul li:hover {
text-decoration:none;
color:#999;
font-weight:bold;
background:url(images/circle_grey.gif) right center no-repeat;
}
try and rewrite the following rule:
.main_menu ul li a {
padding-right: 25px;
text-decoration:none;
color:#999;
display:block;
}
Hey i think you can give to
anchor tag display: inline-block; or give to line-height
as like this
.main_menu ul li a{
display:inline-block;
line-height:35px;
}
Your background is attached to a anchor tag (.main_menu ul li a) and is therefor sized after font-size. To see the whole background file, you need to make anchor element to block or you can use padding.
Use:
display: inline-block;
or
display: block;
or use padding for .main_menu ul li a
You just need to define display:inline-block; in your li a see your updated css :-
.menu_container{
position: absolute;
float: left;
width: 270px;
margin-top: 220px;
}
.main_menu ul {
padding: 0px;
margin:0px;
list-style-type: none;
}
.main_menu ul li {
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
letter-spacing:4px;
text-align:right;
line-height:35px;
list-style-type:none;
}
.main_menu ul li a {
padding-right: 25px;
text-decoration:none;
font-weight:bold;
color:#999;
display:inline-block;
}
.main_menu ul li a.selected {
color: #bc4c9b;
font-weight:bold;
background: url(http://i.imgur.com/TXNfW.gif) right center no-repeat;
}
.main_menu ul li a:hover {
text-decoration:none;
color: #595959;
font-weight:bold;
background:url(http://i.imgur.com/5Ic6o.gif) right center no-repeat;
}
see the demo:- http://jsbin.com/agavid/13/edit
I'm making a CSS dropdown menu. So, when the mouse hovers one menu item, it displays its subitens. Well, all is working fine except the position of submenus. What I got is this:
|Menu 1| |Menu 2|
|Submenu 1|
|Submenu 2|
|Submenu 3|
But I have to change this layout into this, when the mouse hovers a item:
|Menu 1| |Menu 2|
|Submenu 1|
|Submenu 2|
|Submenu 3|
I don't know if it's even possible to make that change.
CSS
.menu{
border:none;
border:0px;
margin:0px;
padding:0px;
font: 67.5% "Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
float: right;
width: auto;
}
.menu ul{
background:#EBF0FD;
line-height: 2.0em;
list-style:none;
margin:0;
padding:0px;
}
.menu li{
float:left;
padding:0px;
}
.menu li a{
background:#EBF0FD url("images/seperator.gif") bottom right no-repeat;
color:#336699;
display:block;
font-weight:normal;
line-height:2.0em;
margin:0px;
padding:0px 25px;
text-align:center;
text-decoration:none;
}
.menu li a:hover, .menu ul li:hover a{
background: #5E78B5 bottom center no-repeat;
color:white;
text-decoration:none;
}
.menu li ul{
background:#EBF0FD;
display:block;
float: left;
height:auto;
padding:0px;
margin:0px;
border-style:solid;
border-color:#C9D8FF;
position:absolute;
width:auto;
z-index:200;
}
.menu li:hover ul{
display:block;
}
.menu li li {
background: bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:225px;
color: red;
}
.menu li:hover li a{
background:none;
color: #336699;
}
.menu li ul a{
display:block;
line-height:35px;
font-size:12px;
font-style:normal;
margin:0px;
padding:0px 10px 0px 15px;
text-align:left;
}
.menu li ul a:hover, .menu li ul li:hover a{
background:#5E78B5 left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
}
.menu p{
clear:left;
}
HTML
<div class="menu">
<ul>
<li>
Menu 1
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
</ul>
</li>
</ul>
</div>
SOLUTION:
Andres Ilich's code have solved my problem (Thanks!). Now, all submenus upper right edge is correctly aligned with the bottom right edge of the top menus. However, there was a problem when several menus itens (top level) were in the layout so that they appeared in vertical, not horizontal. I was able to correct it. So, I'm posting the final working CSS if anyone is also facing this problem. Thanks for helping!
.menu {
font-size:14px;
font-weight:bold;
float: right;
width: auto;
}
.menu ul {
background:#EBF0FD;
line-height: 2.0em;
list-style:none;
margin:0;
padding:0px;
font-family: Verdana, Geneva, sans-serif;
}
.menu li {
float:left;
padding:0;
margin:0;
position:relative;
}
.menu li a {
background:#EBF0FD;
color:#336699;
display:block;
font-weight:bold;
line-height:2.0em;
margin:0px;
padding:0px 25px;
text-align:center;
text-decoration:none;
}
.menu li a:hover, .menu ul li:hover a {
background: #5E78B5 bottom center no-repeat;
color:white;
text-decoration:none;
}
.menu li ul {
background:#EBF0FD;
display:none;
float: left;
height:auto;
padding:0px;
margin:0px;
border-style:solid;
border-color:#C9D8FF;
position: absolute;
right: 0;
width:auto;
z-index:200;
}
.menu li:hover ul {
display:block;
}
.menu li li {
background: bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:200px;
}
.menu li:hover li a {
background:none;
color: #336699;
}
.menu li ul a {
display:block;
line-height:35px;
font-size:12px;
font-style:normal;
margin:0px;
padding:0px 21px;
text-align:right;
}
.menu li ul a:hover, .menu li ul li:hover a {
background:#5E78B5 left no-repeat;
color:#ffffff;
text-decoration:none;
}
You can absolutely position your submenu and just align it to the right most part of your main menu, like so:
First declare your li items as relative, to position the submenu properly:
.menu li {
float: left;
padding: 0;
position: relative;
}
Then declare your submenu as position:absolute along with the right:0 property, to position your submenu absolutely to the right edge of your main menu:
.menu li ul {
position: absolute;
right: 0;
}
And then just position your submenu text to the right to complete the effect:
.menu li ul a {
text-align:right;
}
Edit: Demo
Try this
.menu li ul { display:block; margin-left: -130px; }
jsfiddle example:
http://jsfiddle.net/BBJv5/
But you have to know what width the submenu items gonna have, before you do it this way.
see the fiddle for code and demo
Fiddle: http://jsfiddle.net/dMCKD/1/
Demo: http://jsfiddle.net/dMCKD/1/embedded/result/
Screen Shot: