html - 在 CSS 中将内容置于图像下方

标签 html css

我正在尝试使用 CSS 实现以下目标: enter image description here

内容将由相同大小的 block 组成更宽的网格 - 这只是一个 block 。到目前为止,我有以下 HTML:

<div class="listing_items">
                <!-- listing item 1 -->
                <div class="listing_display">
                    <div class="listing_display_inner">
                        <img src="images/sports/archery_1.png">
                        <div class="listing_item_wrapper">
                            <div class="listing_item_description_1">
                                <div class="listing_item_square"></div>
                                <a href="#" class="listing_item_title">Kelly's Archery Range</a>
                            </div>
                            <div class="listing_item_description_2">
                                <a href="#" class="listing_item_city">Zurich</a>
                                <a href="#" class="listing_item_country">Switzerland</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

以及以下 CSS:

.listing_items {
    text-align: center;
    width: 100%;
    height: auto;
}

.listing_display {
    display: inline-block;
    height: 380px;
    width: 20%;
    margin: 0px 10px;
    min-width: 380px;
}

.listing_display_inner {
    text-align: center;
}

.listing_display_inner>img {
    display: inline-block;
    height: 300px;
    width: 380px;
}

.listing_item_wrapper {
    text-align: center;
    width: 20%;
    height: 50px;
    margin: 0px auto;
}

.listing_item_description_1 {
    float: left;
    display: block;
    width: 200px;
    height: 50px;
}

.listing_item_description_2 {
    display: inline-block;
    width: 150px;
    height: 50px;
}

而且我还远远没有做对......

我正在努力使图片下的内容执行以下操作: 1)始终保持图片上的排列。左边是名字,右边是城市(位置)。 2) 如果名称变得太长,它就转到下一行

谁能帮我弄清楚我做错了什么?

谢谢!

最佳答案

我能得到的最接近的东西,不用把它全部拆掉重新开始。

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.listing_items {
  text-align: center;
  width: 100%;
  height: auto;
}
.listing_display {
  display: inline-block;
  height: 380px;
  width: 20%;
  margin: 0px 10px;
  min-width: 380px;
  border: 1px solid red;
}
.listing_display_inner {} .listing_display_inner img {
  display: block;
  height: 300px;
  width: 380px;
}
.listing_item_wrapper {
  /* quick clearfix */
  overflow: hidden;
}
.listing_item_description_1 {
  float: left;
  width: 50%;
  height: 50px;
  text-align: left;
  background: ;
}
.listing_item_description_2 {
  float: right;
  width: 50%;
  text-align: right;
}
<div class="listing_items">
  <!-- listing item 1 -->
  <div class="listing_display">
    <div class="listing_display_inner">
      <img src="http://lorempixel.com/output/sports-q-c-380-380-10.jpg">

      <div class="listing_item_wrapper">
        <div class="listing_item_description_1">
          <div class="listing_item_square"></div>
          <a href="#" class="listing_item_title">An incredbible baseball display</a>
        </div>
        <div class="listing_item_description_2">
          <a href="#" class="listing_item_city">Zurich</a>
          <a href="#" class="listing_item_country">Switzerland</a>
        </div>
      </div>
    </div>
  </div>
</div>

Codepen Demo

关于html - 在 CSS 中将内容置于图像下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31453086/

相关文章:

html - 动画div从另一个div中的底部滑动

javascript - 如何更改 Bootstrap slider 的大小?

css - 没有媒体类型的@media 规则是做什么的?

css - 如何允许在网页中水平滚动

商业网络应用的 CSS/其他模板

html - 如何水平居中 <div> block 元素?

javascript - 如何垂直移动相反方向的两个列表

javascript - 如何让 CSS3 动画在向下滚动时播放并在向上滚动时反向播放?

html - CSS - 如果溢出则锁定滚动条

html - 在 <a> 中移动文本