【发布时间】:2026-02-16 23:00:01
【问题描述】:
我正在尝试在我正在制作的画廊网格前面添加带有边框的标签作为图层。
我的代码是这样的:
HTML
<div class="wrap">
<div class="grid-item25"> <a href="#" class="bordered">
</a>
<img src="http://placehold.it/400x400" />
<a href="#" style="display:block;">test</a>
</div>
<div class="grid-item25"> <a href="#" class="bordered">
</a>
<img src="http://placehold.it/400x400" />
<a href="#" style="display:block;">test</a>
</div>
</div>
CSS
*,
*:after,
*:before {
margin: 0;
padding: 0;
/* Removes padding behaviour on widths */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
img {
max-width: 100%;
height: auto;
}
.wrap {
max-width: 100%;
width: 100%;
background-color: black;
}
.wrap:after {
content:"";
display: table;
clear: both;
}
.grid-item25 {
max-width: 25%;
min-height: 202px;
float: left;
display: block;
padding: 5px;
position: relative;
}
.bordered {
text-decoration: none;
position: absolute;
z-index: 90000;
border:1px solid white;
left: 1rem;
right: 1rem;
top:1rem;
bottom:1rem;
}
结果是这样的:http://jsfiddle.net/ditikos/7LGBD/,但问题是边框不是停留在图像底部(0.5rem),而是溢出到文本中。
有人可以帮助我理解为什么会发生这种情况,并且它没有停留在应有的位置吗?
谢谢
【问题讨论】:
-
是的,但已插入。如果没有文本,它会完美放置,但添加它会使绝对定位到整个网格高度(包括图像)。
-
你能试着在这里进一步解释你需要什么吗?我有一种感觉你在叫错树,但我无法从解释中看出你想要什么。如果您需要图像也是可点击的链接,请将
嵌套在 html 中的 内。
-
这就是 zeroworks 试图展示的。我正在尝试制作一个响应式图像,其边框会增长/缩小并且小于图像的宽度/高度