html - 在图片下定位 flexbox 中的文本

标签 html css text flexbox positioning

我的文本出现问题,我根本看不到它,或者它不像我认为它会在 flexbox 中那样工作。我现在在 flexbox 中有三张图片,但我想在每张图片下面放置小的“标题”(不是在 p 元素中,紫色,但我想把它放在白色上,它就在紫色框(p 元素)。我认为通过添加一个子元素,该元素至少会与其上方的元素垂直对齐,但我想我错了。有人能帮忙吗?另一条信息是我的图片是 250 像素,但我想容纳一个片段,所以我把它设为 50 像素,但这可能无关紧要。

#footer {
  display: flex;
  height: 130px;
  width: 100%;
  background-color: #862d59;
  clear: both;
}

#footer, #wrapper:after{
  height: 130px;
}

.wrap {
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}

.sub {
  padding: 12px;
  width: 32%;
  height: 100px;
  color: white;
  border-right: solid white 1px;
}

.sub:last-child {
  border: 0px;
}

html {
  height: 100%;
}

body {
  height: 100%;
  margin:0;
  font-family: courier;
  font-size: 22px;
  color: white;
}

#wrapper {
  position: relative;
  margin-left: auto;
  margin-right: auto;
  width: 85%;
  min-height: 100%;
  margin-top: -130px;
}

#inner {
  position:absolute;
  display:flex;
  flex-wrap: wrap;
  height: 600px;
  top:50%;
  align-items: center;
  justify-content: space-between;
  margin-top: -300px;
  align-content: center;
  width: 100%;
}

#inner p {
  background-color: #26004d;
  padding: 60px;
  border-radius: 9px;
}

#inner img {
  border-radius: 8px;
}
<div id="wrapper">
  <div id="inner">
    <p><img src="cat1.jpeg" alt="Picture of a cat" width="50" height="50"></p>
    <p><img src="dog1.jpg" alt="Picture of a cat" width="50" height="50"></p>
    <p><img src="park.jpg" alt="Picture of a cat" width="50" height="50"></p>
  </div>
</div>
<div id="footer">
  <div class="wrap">
    <div class="sub"></div>
    <div class="sub"></div>
    <div class="sub"></div>
  </div>
</div>

最佳答案

没有其他信息/图像,这是我能够想出的解决方案。如果您想将每个图像/标题分组在一起,请将它们包装在另一个父 div 中。然后只需在其下方添加标题,这是一个 block 元素,并且应该按预期在图像下方流动。下面的片段。

#footer {
  display: flex;
  height: 130px;
  width: 100%;
  background-color: #862d59;
  clear: both;
}

#footer, #wrapper:after{
  height: 130px;
}

.wrap {
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}

.sub {
  padding: 12px;
  width: 32%;
  height: 100px;
  color: white;
  border-right: solid white 1px;
}

.sub:last-child {
  border: 0px;
}

html {
  height: 100%;
}

body {
  height: 100%;
  margin:0;
  font-family: courier;
  font-size: 22px;
  color: white;
}

#wrapper {
  position: relative;
  margin-left: auto;
  margin-right: auto;
  width: 85%;
  min-height: 100%;
}

#inner {
  position:absolute;
  display:flex;
  flex-wrap: wrap;
  height: 600px;
  top:50%;
  align-items: center;
  justify-content: space-between;
  margin-top: -300px;
  align-content: center;
  width: 100%;
}

#inner p {
  background-color: #26004d;
  padding: 60px;
  border-radius: 9px;
}

#inner p.caption {
  color: #000;
  background-color: transparent;
  border-radius: 0;
}

#inner img {
  display: block;
  border-radius: 8px;
}
<div id="wrapper">
  <div id="inner">
    <div class="image-wrapper">
      <p>
        <img src="http://placehold.it/100x100" alt="Picture of a cat">
      </p>
      <p class="caption">Caption</p>
    </div>
    <div class="image-wrapper">
      <p>
        <img src="http://placehold.it/100x100" alt="Picture of a cat">
      </p>
      <p class="caption">Caption</p>
    </div>
    <div class="image-wrapper">
      <p>
        <img src="http://placehold.it/100x100" alt="Picture of a cat">
      </p>
      <p class="caption">Caption</p>
    </div>
  </div>
</div>
<div id="footer">
  <div class="wrap">
    <div class="sub"></div>
    <div class="sub"></div>
    <div class="sub"></div>
  </div>
</div>

如果您有任何问题,或者这不符合您的描述,请告诉我。

关于html - 在图片下定位 flexbox 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37936381/

相关文章:

java - 如何使用 Selenium Webdriver Java 查找表行号

php - 使用 PHP 和 HTML 中的变量搜索 MySQL

javascript - 如何从网址截取网页快照?

java - 如何使用 CSS 将过滤器应用于 JavaFX?

javascript - 调用 onBlur 时 relatedTarget 在 Firefox 中为 null

Python。 While循环附加txt文件名和新文件名

text - awk - 比较两个文件,匹配一个字段,合并两个文件

html - 如何在同一行对齐两个提交按钮

css - 为什么背景色为 : '#ff0000' ; is an "invalid property value"?

swift - 我如何在 xctest 中找到标签或静态文本的层次结构?