div背景颜色,改变悬停时的背景颜色
我正在尝试使 div 的背景颜色在鼠标悬停时发生变化。
div {背景:白色;}
div a:hover{背景:灰色; 宽度:100%;
显示:块; 文本装饰:无;}
仅 div 内的链接获取背景颜色。
我该怎么做才能使整个div获得背景颜色?
谢谢
编辑:
我怎样才能使整个 div 充当链接 - 当您单击该 div 上的任意位置时,将您带到一个地址。
I'm trying to make a div's background color change on mouse over.
the div {background:white;}
the div a:hover{background:grey; width:100%;
display:block; text-decoration:none;}
only the link inside the div gets the background color.
what could I do to make the whole div get that background color?
thank you
EDIT :
how can I make the whole div to act as a link - when you click anywhere on that div, to take you to an address.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
当鼠标悬停在
标签上时,“
a:hover
”字面意思是告诉浏览器更改该标签的属性。 您的意思可能是“the div:hover
”,它会在选择 div 时触发。只是为了确保,如果您只想更改一个特定的 div,请给它一个 id ("
") 并使用 CSS "
#something :hover {...}
" 代替。 如果要编辑一组 div,请将它们放入一个类 ("") 并使用 CSS "
.else {... }
" 在这种情况下(注意类名称之前的句点!)The "
a:hover
" literally tells the browser to change the properties for the<a>
-tag, when the mouse is hovered over it. What you perhaps meant was "the div:hover
" instead, which would trigger when the div was chosen.Just to make sure, if you want to change only one particular div, give it an id ("
<div id='something'>
") and use the CSS "#something:hover {...}
" instead. If you want to edit a group of divs, make them into a class ("<div class='else'>
") and use the CSS ".else {...}
" in this case (note the period before the class' name!)使用 JavaScript
Using Javascript
无需抛锚。 然后更改 div 悬停时的样式
更改悬停时 div 的背景颜色。
There is no need to put anchor. To change style of div on hover then
Change background color of div on hover.
要使整个 div 充当链接,请将锚标记设置为:
并将锚标记的高度设置为 100%。
然后为您的 div 标签设置固定高度。
然后像往常一样设置锚标记的样式。
例如:
祝你好运!
To make the whole div act as a link, set the anchor tag as:
And set your height of the anchor tag to 100%.
Then set a fixed height to your div tag.
Then style your anchor tag like usual.
For example:
Good luck!
html 代码:
css 代码:
这就是如何通过将鼠标悬停在 div 上将其从红色更改为蓝色。
html code:
css code:
and thats how youll change your div from red to blue by hovering over it.
设置
a并给出一些高度
Set
on a and give some height
只需尝试 CSS 的“hover”属性即可。 例如:
我希望这个能帮上忙
simply try "hover" property of CSS. eg:
i hope this will help
您可以将锚点放在 div 周围。
进而
You can just put the anchor around the div.
and then
您可以将 div 包含在锚标记中,如下所示:
you could just contain the div in anchor tag like this:
只需在 css 文件中设置属性
!important
,这样鼠标悬停时背景颜色就不会改变。这对我有用。例子:
Just make the property
!important
in your css file so that background color doesnot change on mouse over.This worked for me.Example: