简体   繁体   English

悬停时背景颜色变化

[英]Background color change on hover

I have done box around text. 我已经在文本周围做了方框。 Now I want to be hover and change the color of the box 现在我要悬停并更改框的颜色
background. 背景。 I am not able to change that when mouse hover. 当鼠标悬停时,我无法更改该设置。 I have also attached the 我还附上了
image with this so you can have idea about. 图像与此相关,因此您可以了解一下。 I have done box around text. 我已经在文本周围做了方框。 Now I want to be hover and change the color of the box background. 现在,我想悬停并更改框背景的颜色。 I am not able to change that when mouse hover. 当鼠标悬停时,我无法更改该设置。 I have also attached the image with this so you can have idea about.please check the image and found the social media box , when I hover the mouse 我还附带了图像,以便您有想法。请检查图像并在鼠标悬停时找到社交媒体框。
the hover color is not changing. 悬停颜色没有变化。

 <style>
 div.ex
 {
     width:20px;
     height:20px; 
     padding:5px;
     border:1px solid #D8D8D8;
     margin:0px;
     background-color:#3b5998;
 }
 </style>


<div class="ex"><span class="iconfacebook2" aria-hidden="true" data-icon="&#xe169;">     
</span></div> 

查看图片以了解更多想法

*edited to make the image appear *编辑以使图像出现

You can use the :hover selector: 您可以使用:hover选择器:

http://www.w3schools.com/cssref/sel_hover.asp http://www.w3schools.com/cssref/sel_hover.asp

But if you are using images, you can apply CSS Image Sprites: 但是,如果您使用的是图像,则可以应用CSS图像精灵:

http://www.w3schools.com/css/css_image_sprites.asp http://www.w3schools.com/css/css_image_sprites.asp

By the way, if you are developing a website, maybe CSS Image Sprites are a good choice to boost the performance of the website (because it uses only 1 native image for multiple image interactions). 顺便说一句,如果您正在开发一个网站,也许CSS Image Sprites是提高网站性能的一个不错的选择(因为它只使用1个本地图像进行多次图像交互)。

;) ;)

<style>
div.ex
{
width:20px;
height:20px; 
padding:5px;
border:1px solid #D8D8D8;
margin:0px;
background-color:#3b5998;
}
div.ex:hover {
background-color:#000;
}
 </style>

Create a hover element by taking the same css class div.ex and adding :hover 通过使用相同的CSS类div.ex并添加:hover创建一个悬停元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM