![](/img/trans.png)
[英]CSS When hover on a anchor, change the background color of the div it's on
[英]How do I change the link color and background hover with css when it's inside a div tag?
這是一個例子:
#dolls {
position: absolute;
left: 248px;
top: 31px;
width: 150px;
height: 65px;
z-index: 2;
text-align: center;
color: #8C6954;
font-size: 18px;
text-decoration:none;
<div id="dolls"><br><a href="dolls.html">Haunted Dolls</a></div>
我正在嘗試更改鏈接的顏色,懸停和懸停時的背景顏色,但是它不起作用。 我該怎么做呢?
使用a:hover
懸停效果
#dolls { position: absolute; left: 248px; top: 31px; width: 150px; height: 65px; z-index: 2; text-align: center; color: #8C6954; font-size: 18px; text-decoration: none; } div a:hover { background-color: black; color: white; font-weight: bold; }
<div id="dolls"> <br><a href="dolls.html">Haunted Dolls</a> </div> <a href="anotherLink">Some other link</a>
您可以使用偽類hover
和link
a:hover {
// css code
}
a:link {
// css code
}
嘗試這個
的CSS
#dolls a:hover{
color:white;
background:red;
}
把#dolls
在眼前a:hover {
只使a
的在#dolls
得到懸停效果。
#dolls a:hover {
color:blue; // color of text
background-color: green; // background color
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.