[英]Change background-color on hover
我正在嘗試創建一個導航菜單,當我將鼠標懸停在某個項目上時,它將類似於下圖。 現在,盒子只用白色填充一半,但我想用白色填充整個li
。 我在油漆上畫了白線以顯示我要填充的內容
圖片http://oi63.tinypic.com/2wp2jix.jpg
CSS
.lefttabs {
background-color: #1E1E1E;
color: white;
font-family: calibri;
font-weight: bold;
font-size: medium;
width: 300px;
height: 100%;
z-index: 1; /* Stay on top */
padding-top: 60px;
/* Place content 60px from the top */
transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
}
.lefttabs a {
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
font-size: medium;
color: white;
width: 133px;
margin-left: 0;
padding: 8px;
text-decoration: none;
line-height: 24px;
}
.lefttabs ul {
list-style: none;
margin: 0 20px 0 0;
border: 1px solid;
}
.lefttabs li {
list-style: none;
}
.lefttabs li a {
list-style: none;
display: block;
padding: 0 0 30px 0;
padding-left: 10px;
padding-top: 10px;
}
.lefttabs a:hover {
background-color: white;
color: black;
}
.imga {
width: 40px;
height: 30px;
margin-left: -21px;
margin-right: 20px;
}
.lefttabs a imga {
margin: 0 8px 0 0;
vertical-align: middle; /* needed */
}
HTML
<div class="lefttabs">
<ul>
<li>
<a href=""><img class="imga" alt="dashboard" src="images/eve.bmp" border="0" />DASHBOARD</a>
</li>
<li>
<a href=""><img class="imga" alt="Events" src="images/eve.bmp" border="0" />EVENTS</a>
</li>
<li>
<a href=""><img class="imga" alt="Vehicles" src="images/ve.bmp" border="0" />VEHICLES</a>
</li>
</ul>
</div>
嘗試這個
.lefttabs { background-color: #1E1E1E; color: White; font-family: Calibri; font-weight: bold; font-size: medium; width: 300px; height: 100%; z-index: 1; /* Stay on top */ padding-top: 60px; /* Place content 60px from the top */ transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */ } .lefttabs a { font-size: 25px; color: #818181; display: block; transition: 0.3s; font-size: medium; color: White; width: 133px; margin-left: 0px; padding: 8px; text-decoration: none; line-height: 24px; } .lefttabs ul { list-style: none; margin: 0px; border: 1px solid; /* not border:1 px solid*/ padding: 0; /* add this*/ } .lefttabs li { list-style: none; } .lefttabs li a { list-style: none; display: block; padding: 10px 0px 30px 10px; /*padding-left: 10px;*/ /*padding-top: 10px;*/ width: 100%; /*add this*/ } .lefttabs a:hover { background-color: White; color: Black; } .imga { width: 40px; height: 30px; float: left; margin-right: 20px; } .lefttabs a imga { margin: 0 8px 0 0; vertical-align: middle; /* needed */ }
<div class="lefttabs"> <ul> <li> <a href=""> <img class="imga" alt="dashboard" src="images/eve.bmp" border="0" />DASHBOARD </a> </li> <li> <a href=""> <img class="imga" alt="Events" src="images/eve.bmp" border="0" />EVENTS </a> </li> <li> <a href=""> <img class="imga" alt="Vehicles" src="images/ve.bmp" border="0" />VEHICLES </a> </li> </ul> </div>
如果您希望元素采用全角格式,則需要將其設置為display: block
在CSS中display: block
(如果它還不是block
元素)。 此外,在ul
上通常會使用默認margin
並且在大多數瀏覽器中也會應用padding
,您也需要清除這些padding
。 以下是經過修改的CSS,包括其他一些更改...
.lefttabs { background-color: #1e1e1e; color: white; font-family: Calibri; font-weight: bold; font-size: medium; width: 300px; height: 100%; z-index:1; /* Stay on top */ padding-top: 60px; /* Place content 60px from the top */ transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */ } .lefttabs a { font-size: 25px; color: #818181; display: block; transition: 0.3s; font-size:medium; color:White; margin-left: 0; padding: 8px; text-decoration: none; line-height: 24px; } .lefttabs ul { list-style:none; margin:0; border: 1px solid; padding: 0; } .lefttabs li { list-style:none; } .lefttabs li a { list-style:none; display:block; padding: 15px 20px; display: block; } .lefttabs a:hover { background-color: white; color: black; } .imga { display: inline-block; vertical-align: top; width: 40px; height: 30px; margin-right: 20px; margin-top: -3px; } .lefttabs a imga { margin: 0 8px 0 0; vertical-align: middle; /* needed */ }
<div class="lefttabs"> <ul > <li> <a href=""><img class="imga" alt="dashboard" src="images/eve.bmp" border="0" />DASHBOARD</a> </li> <li> <a href=""> <img class="imga" alt="Events" src="images/eve.bmp" border="0" />EVENTS</a> </li> <li> <a href=""> <img class="imga" alt="Vehicles" src="images/ve.bmp" border="0" />VEHICLES</a> </li> <ul> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.