【问题标题】:Aligning text to right bottom of an image将文本与图像的右下角对齐
【发布时间】:2014-03-02 15:43:46
【问题描述】:

我正在使用以下代码将标题与图像的右下角对齐。代码运行良好。

我想知道是否可以重写它不指定图片容器(.picture 类)的最小宽度。调整浏览器窗口大小时,如果没有宽度,标题会向下移动:

<div class="picture">
    <img src="image.jpg">
    <div class='captioning'>
        <div class='title'>text</div>
        <div class='caption'>text</div>
    </div>
</div>

.picture {
    position: relative;
    overflow: hidden;
    min-width: 1200px;
}
.picture img {
    float: left;
}
.picture .captioning {
    float: left;
    width: 150px;
    margin: 0 0 0 15px;
}
.picture .captioning .caption {
    position: absolute;
    bottom: 0;
}
.picture .captioning .title {
    position: absolute;
    bottom: 0;
}

有什么想法吗?

提前致谢

【问题讨论】:

  • “降档”是什么意思?
  • 它在照片下折叠
  • 对不起,我还是不明白你的意思是什么行为
  • 此行为:link
  • 我现在看到了,但我无法重现该行为。也许您可以在 jsFiddle 或类似网站上创建一个示例?

标签: css-float alignment


【解决方案1】:

我找到了解决方案。我在图像和标题上都使用了 display: inline-block,在容器上使用了 white-space: nowrap:

.picture {
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}
.picture img {
    display: inline-block;
}
.picture .captioning {
    display: inline-block;
    width: 150px;
    margin: 0 0 0 15px;
    white-space: normal;
}
.picture .captioning .caption {
    position: absolute;
    bottom: 0;
}
.picture .captioning .title {
    position: absolute;
    bottom: 0;
}

【讨论】:

    猜你喜欢
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 2012-02-24
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 2021-09-10
    相关资源
    最近更新 更多