Reputation: 2185
i have this menu:
<div class="nav">
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">AMORTECIMENTO</a></li>
</ul>
</div>
the normal apearance:
and this is the apearance when users hover the menu:
So, i dont know how to setup the css, assuming i have biggest names on menu like: "AMORTECIMENTO"
Any tips??
i have tried this, but on small names, the menu is cutting the background...
.nav ul li a{
display:block;
font-size:15px;
color:#000;
padding:5px 7px;
background:transparent;
text-decoration:none;
}
.nav ul li:hover{
background:url(../imagens/bola_fundo_menu.png) center no-repeat;
}
My intention is, when user hover the menu item, on the <li>
background, apear the basketball, and on <a>
tag, the background is going to #FFF but i have small and big names on menu, so i can't set width of <li>
and <a>
tags... i think
Upvotes: 0
Views: 4945
Reputation: 2829
Here is a quick example using pseudo-elements: http://codepen.io/anon/pen/iwerJ
Using the exact HTML you originally posted, with CSS like this:
.nav {
background: #CCC;
font-family: Helvetica, Arial, sans-serif;
line-height: 48px;
margin: 50px auto 0;
width: 90%;
}
.nav ul:after {
clear: both;
content: '';
display: block;
}
.nav ul li {
float: left;
font-size: 14px;
list-style: none;
padding: 0 10px;
position: relative;
}
.nav ul li:hover:after {
/* Replace background with image */
background: #abc123;
/* Optionally remove radius */
border-radius: 30px;
content: '';
display: block;
position: absolute;
top: 50%; left: 50%;
margin-top: -30px;
margin-left: -30px;
height: 60px; width: 60px;
}
.nav a {
color: #333;
display: inline-block;
line-height: 180%;
padding: 0 4px;
position: relative;
text-decoration: none;
z-index: 1;
}
.nav li:hover a { background: #FFF; }
Upvotes: 3
Reputation: 3367
Just set a hover background. Eg:
div.nav li:hover{
background-image: url('basketball.jpg');
}
EDIT: You've got a lot more issues than just a background image...
Good luck. I can't write all of that code out for you, but that should send you in the right direction.
Upvotes: 2
Reputation: 5153
To fix the cut-off images, you can simply put a min-width
on your .nav li
elements. Make sure the value is at least as wide as your background images.
You'll probably also want to add text-align: center
.
Upvotes: 0
Reputation: 1986
on your nav class all you have to do is write your css like this:
.nav ul li:hover
{
background-image:url('yourimage.jpg');
}
Upvotes: 0