gpt4 book ai didi

html - 将 div rgba 悬停在背景图像上而不改变文本颜色的不透明度

转载 作者:行者123 更新时间:2023-11-28 09:32:25 27 4
gpt4 key购买 nike

我需要鼠标悬停的 CSS 代码,例如当您将图像悬停时,它会在总 div 的 rgba 中显示 1px 的边框颜色和超过颜色不透明度,但不会改变 h3 标签中和前后文本的不透明度。同时悬停文字和前后颜色会像附图一样改变。我知道我的 CSS 代码是错误的,尽管我放在这里。这是 jsFiddle Demo

这里分别是html和css代码---

HTML:

<div class="service-single-box relax-massage">
<h3 class="service-title">Relax Massage</h3>
</div>

CSS:

.service-single-box {

cursor: default;
margin-top: 15px;
margin-bottom: 15px;
overflow: hidden;
position: relative;
text-align: center;
height: 136px;
}


.service-single-box:hover, .service-single-box:focus{

background-color:rgba(0,0,0,0.5);
border-top: 1px solid #ab9661;
border-left: 1px solid #ab9661;
border-bottom: 2px solid #ab9661;
border-right: 2px solid #ab9661;
cursor: default;

}


.service-single-box img:hover, .service-single-box img:focus{

background-color: #282318;
border: 1px solid #ab9661;
cursor: default;
background-color:rgba(0,0,0,0.5);

}


.relax-massage{

background-image: url("../images/services.png");
}

.relax-massage h3{

color:#fdfdfb;
text-transform: uppercase;
font-size: 16px;
font-weight: bold;
width: 170px;
padding-top: 20px;
}


.relax-massage h3:hover{

color:#a4905d;
}


.relax-massage h3:before {

width: 28%;
background: none repeat scroll 0 0 #fdfdfb;
border-top: 1px solid #fdfdfb;
content: "";
height: 5px;
top: 28px;
position: absolute;
}

最佳答案

像这样更改您的 CSS(主要是您所做的一些可视化更改以及使其按您想要的方式工作所需的更改):

body{background:#333;}
.service-single-box {
cursor: default;
margin-top: 15px;
margin-bottom: 15px;
overflow: hidden;
position: relative;
text-align: center;
width:200px;
height: 136px;

}


.service-single-box:hover, .service-single-box:focus{
background-color:rgba(0,0,0,0.5);
border-top: 1px solid #ab9661;
border-left: 1px solid #ab9661;
border-bottom: 2px solid #ab9661;
border-right: 2px solid #ab9661;
cursor: default;

}


.service-single-box img:hover, .service-single-box img:focus{
background-color: #282318;
border: 1px solid #ab9661;
cursor: default;
background-color:rgba(0,0,0,0.5);

}


.relax-massage{
background-image: url("http://images.nationalgeographic.com/wpf/media-live/photos/000/750/cache/5-week-in-space-278_75042_600x450.jpg");
border:1px solid
}

.relax-massage h3{
color:#fdfdfb;
text-transform: uppercase;
font-size: 16px;
font-weight: bold;
width: 170px;
padding-top: 20px;
}


.relax-massage h3:hover{
color:#a4905d;
}


.relax-massage h3:before {

width: 28%;
background: none repeat scroll 0 0 #fdfdfb;
border-top: 1px solid #fdfdfb;
content: "";
height: 5px;
top: 28px;
position: absolute;
}

.relax-massage:hover > h3:before{
background:#a4905d;
border-top:none;
}

你可以看到一个fiddle here

透明更新:

HTML代码:

<div class="service-single-box relax-massage">
<div class="overlay">
<h3 class="service-title">Relax Massage</h3>

</div>
</div>

CSS 代码:

body {
background:#333;
}
.service-single-box {
cursor: default;
margin-top: 15px;
margin-bottom: 15px;
overflow: hidden;
position: relative;
text-align: center;
width:200px;
height: 136px;
}
.service-single-box:hover, .service-single-box:focus {
background-color:rgba(0, 0, 0, 0.5);
border-top: 1px solid #ab9661;
border-left: 1px solid #ab9661;
border-bottom: 2px solid #ab9661;
border-right: 2px solid #ab9661;
cursor: default;
}
.service-single-box img:hover, .service-single-box img:focus {
background-color: #282318;
border: 1px solid #ab9661;
cursor: default;
background-color:rgba(0, 0, 0, 0.5);
}
.relax-massage {
background-image: url("http://images.nationalgeographic.com/wpf/media-live/photos/000/750/cache/5-week-in-space-278_75042_600x450.jpg");
border:1px solid #333;
}
.relax-massage h3 {
color:#fdfdfb;
text-transform: uppercase;
font-size: 16px;
font-weight: bold;
width: 170px;
padding-top: 35px;
}
.overlay:hover > h3 {
color:#a4905d;
}
.relax-massage h3:before {
width: 28%;
background: none repeat scroll 0 0 #fdfdfb;
border-top: 1px solid #fdfdfb;
content:"";
height: 5px;
top: 28px;
position: absolute;
}
.overlay:hover > h3:before {
background:#a4905d;
border-top:none;
}
.overlay {
background:transparent;
display:block;
width:100%;
height:100%;
position:relative;
top:-15px;
}
.overlay:hover {
background:rgba(0, 0, 0, 0.5)
}

关于html - 将 div rgba 悬停在背景图像上而不改变文本颜色的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25657884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com