html - 如何将文本放在预先存在的边框内

标签 html css

我正在创建一个致敬页面,我在边框中有一个图像,但我还想在图像下方的边框内添加文本。

我试过将文本和图像放在同一个类 css 中并给它们相同的 id。

#image {
  max-width: 400px;
  border: 5px solid gray;
  padding: 50px;
}

.border {
  border: 5px solid gray;
}
<img id="image" class="border" src="https://c2.staticflickr.com/4/3689/10613180113_fdf7bcd316_b.jpg" <figcaption id="img-caption" class="border"><em><a href=https://en.wikipedia.org/wiki/Norman_Borlaug target="_blank"> Dr. Norman Borlaug</a>, third from the left, trains biologists in Mexico on how to increase wheat yields - part of his life-long war on hunger.</em></figcaption>
</div>

我希望图像和图片在同一边框内,但它们不是。

最佳答案

您在各个元素上都有自己的类(class)。您需要为外部 div 提供类边框,并从图像本身中删除边框 css。

因为您要为单个元素提供边框类和/或边框样式。它出现在他们周围。

#image {
  max-width: 400px;
  padding: 50px;
}

.border {
  border: 5px solid gray;
}
<div class="border">
  <img id="image" src="https://c2.staticflickr.com/4/3689/10613180113_fdf7bcd316_b.jpg" />
  <figcaption id="img-caption">
    <em>
        <a href=https://en.wikipedia.org/wiki/Norman_Borlaug target="_blank"> Dr. Norman Borlaug
        </a>, third from the left, trains biologists in Mexico on how to increase wheat yields - part of his life-long war on hunger.   
    </em>
  </figcaption>
</div>

关于html - 如何将文本放在预先存在的边框内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57031916/

相关文章:

javascript - 如何将参数从 razor 发送到 JavaScript 函数

html - 如何确定特定浏览器版本是否实现了特定的 HTML 5 功能?

html - Firefox 中 Flexbox 中的垂直滚动渲染问题

jquery - 如何让 colorbox 看起来像示例 3 Colorbox?

jquery - 无法将鼠标悬停在 jquery 切换的子菜单上

html - css 中的第 nth-of-type 和 nth-child 无法正常工作

PHP 上传循环数组

javascript - 如何使用原型(prototype)从包装器 div 获取所有外部(父)div id 值?

jquery - 使用 jQuery 获取边框样式

html - 如何在 WordPress 中显示特定帖子的标签