我在井内有一个image
。
当悬停图像/井时,叠加信息显示(目前这是正确的)。
覆盖层应覆盖图像所在的整个孔(灰色部分)。 product-title
位于图像/孔下方,与井分开。
因此,当悬停时product-title
不应受到影响(实际上应该是红色background
,文字字体color
应该变为白色)。
现在如何实现包括product-title
在内的整个事物在悬停时变成灰色?
所以实际上现在一切都很好,只有当徘徊product-title
div应该有自己的风格而不是"隐藏"通过灰色叠加。
.product-detailsmas .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
border-radius: 0;
background: #F7F7F7;
color: blue;
text-align: center;
padding: 10px;
border-top: 1px solid #A10000;
/* vertical-align: middle; */
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
.product-detailsmas {
background-color: #E6E6E6;
text-align: center;
}
.product-detailsmas:hover .overlay {
opacity: 1;
}
.well.sb .product-titlesidebar {
font-size: 13px;
font-family: 'Montserrat',sans-serif;
color: #444;
font-weight: 700;
line-height: 1.25em;
margin: 5px;
}

<div>
<a href="#" target="_blank">
<div class="product-detailsmas">
<div class="image-video-linksidebar">
<img alt="#" src="http://lorempixel.com/100/100">
<div class="brandmas">
BRAND
</div>
<div class="categorymas">
CATEGORY
</div>
</div>
<div class="overlay">
<div class="intro-descriptioncar">
Intro description car
</div>
<div class="userfield1car">
Userfield-1-car
</div>
<div class="userfield1car">
Userfield-2-car
</div>
<div class="userfield1car">
Userfield-3-car
</div>
</div>
</div>
<div class="product-titlesidebar">
CAR TITLE BRAND CATEGORY MODEL-THIS SHOULD NOT BE AFFECTED BY THE OVERLAY HOVER
</div><!--</div>--></a>
</div>
&#13;
答案 0 :(得分:1)
您需要在父position:relative
中设置.product-detailsmas
,否则position:absolute
设置为原样,会使元素脱离流,而不是父元素。< / p>
并通过将product-titlesidebar
.product-detailsmas
注意,因为您使用的是width/height:100%
+ padding
,您需要box-sizing
才能避免使用滚动条
.product-detailsmas {
position: relative
}
.product-detailsmas .overlay {
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
border-radius: 0;
background: #F7F7F7;
color: blue;
text-align: center;
padding: 10px;
border-top: 1px solid #A10000;
/* vertical-align: middle; */
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
.product-detailsmas {
background-color: #E6E6E6;
text-align: center;
}
.product-detailsmas:hover .overlay {
opacity: 1;
}
.well.sb .product-titlesidebar {
font-size: 13px;
font-family: 'Montserrat', sans-serif;
color: #444;
font-weight: 700;
line-height: 1.25em;
margin: 5px;
}
&#13;
<div>
<a href="#" target="_blank">
<div class="product-detailsmas">
<div class="image-video-linksidebar">
<img alt="#" src="http://lorempixel.com/100/100">
<div class="brandmas">
BRAND
</div>
<div class="categorymas">
CATEGORY
</div>
</div>
<div class="overlay">
<div class="intro-descriptioncar">
Intro description car
</div>
<div class="userfield1car">
Userfield-1-car
</div>
<div class="userfield1car">
Userfield-2-car
</div>
<div class="userfield1car">
Userfield-3-car
</div>
</div>
</div>
</a>
</div>
<div class="product-titlesidebar">
CAR TITLE BRAND CATEGORY MODEL-THIS SHOULD NOT BE AFFECTED BY THE OVERLAY HOVER
</div>
&#13;
答案 1 :(得分:1)
ADD :position: relative;
到.product-detailsmas
CSS。
这会将绝对定位元素限制为父元素。
删除:.product-detailsmas .overlay
上的填充 - 这会导致叠加层大于父级。
.product-detailsmas .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
border-radius: 0;
background: #F7F7F7;
color: blue;
text-align: center;
border-top: 1px solid #A10000;
/* vertical-align: middle; */
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
.product-detailsmas {
background-color: #E6E6E6;
text-align: center;
position: relative;
}
.product-detailsmas:hover .overlay {
opacity: 1;
}
.well.sb .product-titlesidebar {
font-size: 13px;
font-family: 'Montserrat',sans-serif;
color: #444;
font-weight: 700;
line-height: 1.25em;
margin: 5px;
}
<div>
<a href="#" target="_blank">
<div class="product-detailsmas">
<div class="image-video-linksidebar">
<img alt="#" src="http://lorempixel.com/100/100">
<div class="brandmas">
BRAND
</div>
<div class="categorymas">
CATEGORY
</div>
</div>
<div class="overlay">
<div class="intro-descriptioncar">
Intro description car
</div>
<div class="userfield1car">
Userfield-1-car
</div>
<div class="userfield1car">
Userfield-2-car
</div>
<div class="userfield1car">
Userfield-3-car
</div>
</div>
</div>
<div class="product-titlesidebar">
CAR TITLE BRAND CATEGORY MODEL-THIS SHOULD NOT BE AFFECTED BY THE OVERLAY HOVER
</div><!--</div>--></a>
</div>
我知道它在技术上还可以,但我个人不在锚标记内加载一堆独立的div。