小编Tod*_*ick的帖子

设置负边距,即其高度的百分比。纯 CSS

我有一系列图像,它们有不同的标题。这些标题中的每一个都需要看起来漂浮在图像底部的中间。这是它的外观以及我如何在 div 中构建它的模型。因为标题底部和下面的任何 div 之间需要有空间,所以标题不能绝对定位。

我知道这可以在 javascript 中完成,但这将是一个黑客,所以我更愿意找到一个只使用 CSS 的解决方案。

查看我的线框模型的图像

...这是到目前为止的代码:JS FIDDLE

.outer {
  position: relative;
  width: 320px;
  margin-bottom:24px // this needs to be the space between the bottom of the caption and the next image or whatever div is beneath.
}

.image {
  background-color: blue;
  width: 320px;
  height: 380px;
  position: relative;
  border-radius: 5px;
}

.caption {
  position: relative;
  margin-top: -24px;
  /* THIS NEEDS TO BE 50% of the Captions variable height */
}

.card {
  margin-right: 25%;
  margin-left: …
Run Code Online (Sandbox Code Playgroud)

css margin caption

8
推荐指数
3
解决办法
6820
查看次数

标签 统计

caption ×1

css ×1

margin ×1