html - 将鼠标悬停在图像上时切换颜色

标签 html css wordpress

我用 CSS 创建了一个 html 代码,它显示下面的图像 1(左图)。我想要完成的是,当您将鼠标悬停在图像 1 上时,我希望出现图像 2(右图)(不要介意大小差异)。

Image 1 Image2

HTML:

<body>
    <div class="borderbox">
        <h3 class="header-3">+</h3>
        <p class="paragraph-text">visa fler bästsäljare</p>
    </div>
</body>

CSS:

.borderbox {
    border-style: dashed;
    border-width: 2px;
    border-color: #d3d3d3;
    position: absolute;
    height: 362px; !important
    width: 241px;  !important
    top: 0;
    left: 0;
    margin-right: 5%;      
}

h3.header-3 {
    font-size: 130px;
    text-align: center;
    color: #00a0df;
    margin: 4px auto 17px;
}

p.paragraph-text {
    font-size: 20px;
    text-align: center;
    color: #00a0df;
    text-transform: uppercase;
    font-family: inherit; font-weight: bold;

}

当您将鼠标悬停在图像 1 上时,我希望它切换颜色(图像 2),我该如何将此实现到我的 CSS。蓝色的颜色代码是 #00a0df

URL to my website

最佳答案

color: #00a0df; 添加到 borderbox 并将文本的颜色更改为 color: inherit。然后在悬停时,您可以更改 background-color、文本 colorborder 颜色和任何其他您想要的颜色:

.borderbox {
    border-style: dashed;
    border-width: 2px;
    border-color: #d3d3d3;
    position: absolute;
    height: 362px; !important
    width: 241px;  !important
    top: 0;
    left: 0;
    margin-right: 5%; 
    color: #00a0df; //add
}


h3.header-3 {
    font-size: 130px;
    text-align: center;
    color: inherit; //change
    margin: 4px auto 17px;
}



p.paragraph-text {
    font-size: 20px;
    text-align: center;
    color: inherit; //change
    text-transform: uppercase;
    font-family: inherit; font-weight: bold;

}

.borderbox:hover{
    background-color: #00a0df;
    color: #FFF;
    border-color: #FFF;
}

FIDDLE

关于html - 将鼠标悬停在图像上时切换颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28013912/

相关文章:

javascript - jQuery Ready 的两个定义

html - 表单操作属性中的片段标识符

html - 悬停、z-index 和分层……一团糟?

html - Div中图片的垂直对齐方式

javascript - Android 手机上的 HTML5 Canvas - 重绘和高亮问题

css - 如何在包含多个引导行的两列之间添加垂直分隔符?

html - Css 中心对齐菜单?

css - 在 IE 10 的 .before 错误之前跨越 div

php - 在 WooCommerce 中向非成员(member)显示成员(member)折扣价

php - Wordpress 仅在启用缓存时返回未找到的文件