将图像标题区域与图像对齐
Aligning image caption area with image
我在 Angular 中有一个组件,它将产品集合显示为四列网格中的图像。
<div class="row" ng-repeat="product in products track by $index" ng-if="$index % 4 == 0">
<div class="col-sm-3 title-box-sm" ng-repeat="i in [$index, $index + 1, $index + 2, $index + 3]" ng-if="products[i] != null" ng-class="{hover: hover}" ng-mouseenter="hover = true" ng-mouseleave="hover = false">
<a href="{{ products[i].url }}">
<img alt="{{ products[i].alt }}" ng-src="{{ products[i].image_url }}"/>
<div class="image-caption">
{{ products[i].name }}
</div>
</a>
</div>
我希望能够将鼠标悬停在图像上并使其弹出,在其下方显示显示其他信息的标题区域。 弹出窗口工作正常,但其下方的标题不对齐。 这似乎与它的立场是绝对的事实有关。 这些是应用于此效果的相关样式规则是
.title-box-sm.hover {
-moz-transform: scale(1.03);
-o-transform: scale(1.03);
-webkit-transform: scale(1.03);
transform: scale(1.03);
z-index: 600;
}
.title-box-sm.hover .image-caption {
display: block;
position: absolute;
background: white;
width: 100%;
line-height: 3.4em;
}
但它在右侧没有正确排列,任何添加到图像标题的填充都会进一步将其推出。 它需要是一个绝对位置,以便在悬停在它上面时不会将其他所有内容推倒。 如何使标题始终与图像的左侧和右侧对齐,无论我如何设置图像标题容器的样式? 抱歉,如果已经回答了这个问题,我找不到相关文章。
这可能是因为您的 CSS 设置为使标题宽度为 100%,而不是实际的图像宽度。我去掉了棱角分明的东西,因为它不相关,并创建了一个快速的小提琴来展示我认为你想要的东西。
固定宽度:https://jsfiddle.net/w3nc95dg/流体宽度:https://jsfiddle.net/w3nc95dg/4/
我所做的 CSS 更改:
.title-box-sm:hover {
-moz-transform: scale(1.03);
-o-transform: scale(1.03);
-webkit-transform: scale(1.03);
transform: scale(1.03);
z-index: 600;
}
.title-box-sm .image-caption {
display: none;
position: absolute;
text-align:center;
background: #66ffff;
/*width: 100px;*/
left: 15px;
right: 15px;
line-height: 3.4em;
}
.title-box-sm:hover .image-caption {
display: block;
}
相关文章:
- 如何在JavaScript图像滑块内居中对齐图像
- 以Jquery为中心的Div中的图像对齐
- 使用jquery垂直对齐动态加载的图像
- 使用绝对css将图像与正在换行的文本对齐
- 如何在CSS中将文本相互对齐并使图像宽度为屏幕
- Js 图像滑块,中间垂直对齐
- Css浮动:右100%高度,图像底部对齐
- 范围滑块,用于更改轨道上方对齐圆的直径并使对齐的图像显示在下方
- 在横幅中水平对齐图像和 JavaScript 旋转图像
- 将图像标题区域与图像对齐
- 如何在使用文本对齐时调整图像大小并保持图像映射坐标:居中
- 主页上的居中对齐图像 WordPress.
- 将文本与对话框中标题栏中的图像对齐
- 对齐引导轮播图像
- 从 JSON 检索数据时 HTML 图像未正确对齐
- 将对象(图像)与底部对齐
- 自适应布局上的垂直自适应图像对齐
- jQuery插件光滑的Carousel图像对齐
- 固定滑块与背景图像对齐
- 将重复的背景图像与容器底部的非重复背景图像对齐