html - 如何将标题与图像对齐?

标签 html css

我想询问如何将标题与图像对齐,我的文本很长。可能吗?

<figure>
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=330%C3%97180&w=330&h=180">
<figcaption>Adjusting to school is a noteworthy move in a youthful grown-up's life. For some, the move incorporates moving out of the family home surprisingly, making new companions, and confronting expanded academic demands.
</figcaption>
</figure>

CSS

figure {
display: inline-block;
margin: 20px;
}

figure img {
vertical-align: top;
}

figure figcaption {
text-align: center;
}

上面的代码导致了这个;

I COULDN'T UPLOAD IT BECAUSE IT SAYS I NEED 10 REPS TO POST IMAGES, I'M VERY VERY SORRY

最佳答案

用图像的宽度组成一个div即可。然后使用该图像作为背景图像并将内容对齐在 div 的中间。

示例如下:

.div{
display: flex;
height: 200px;
width: 100%;
background-image: url("paper.gif");
}

.caption{
margin: auto;
}

关于html - 如何将标题与图像对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43365957/

相关文章:

javascript - 在 JavaScript 中实现图像

jquery - 响应式 Accordion ,右侧有数据

html - 如何在 HTML 中获取元素的位置和大小

css - 使用 bootstraps btn-group-justified 布局时是否可以使用不同宽度的按钮?

javascript - ChartJS 水平图表在每个条形上显示图例

php - 在 wordpress 中更改小部件内的默认 HTML 标记

css - 在 HTML 中定义我自己的标签

html - 使 Bootstrap 输入字段保持一致

javascript - bootstrap 下拉菜单在小屏幕上落后于内容

html - 相对div定位?