【问题标题】:How to get captions over images in a responsive grid?如何在响应式网格中获取图像的标题?
【发布时间】:2014-04-03 17:34:11
【问题描述】:

我有一个响应式图像网格,我想在图像上添加标题。通过将position:absolutebottom:0 用于.title div(标题div),我得到了图像上的标题,但我无法让它们的宽度与图像的宽度相同 - 并且反应灵敏。设置width:100% 我让它们比图片更宽。


HTML:

<ul class="grid">
  <li>
    <div class="photo">
      <img src="sampleimg.jpg">
      <div class="title">
        <h3>Image Title</h3>
        <a href="#">Link</a>
      </div>
    </div>


CSS:

.photo {
    margin: 0;
    position: relative;
}

.photo img {
    display: block;
    position: relative;
    max-width: 100%;
    height: auto;
}

.title {
    padding: 20px;
    background: #2c3f52;
    color: #ed4e6e;
    height:auto;
    position:absolute;
    bottom:0;
}

【问题讨论】:

    标签: css image html responsive-design


    【解决方案1】:

    试试这个:

    .photo, .photo * {
      -moz-box-sizing: border-box;
     -webkit-box-sizing: border-box;
     box-sizing: border-box;
     }
    
    .title {
        padding: 20px;
        background: #2c3f52;
        color: #ed4e6e;
        height:auto;
        position:absolute;
        bottom:0;
        left:0;
        right:0;
    }
    

    【讨论】:

    • 非常感谢! :) 完美运行!
    • 关于如何使用 Rails 实现这一点并使其具有动态性的任何想法?
    猜你喜欢
    • 2020-01-27
    • 2017-08-28
    • 2013-09-29
    • 2017-01-12
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多