简体   繁体   English

标题与图像并排对齐

[英]Aligning images with captions side by side

So I've spent the last hour or so trying to figure out how to put captioned images next to each other. 因此,我花了最后一个小时左右的时间来弄清楚如何将带字幕的图像彼此相邻放置。 Most solutions/questions other people have don't work when I try to add text below it using figcaption or something of that sort. 当我尝试使用figcaption或类似的东西在其下方添加文本时,其他人无法解决的大多数解决方案/问题。

I want the text to be underneath the images and move with the images but for some reason it moves the other image to another layer when I add text. 我希望文本位于图像下方并随图像一起移动,但是由于某种原因,当我添加文本时,它将其他图像移至另一层。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

(This is only a small portion of it because there's a lot of other stuff not related to this issue in that style) (这只是其中的一小部分,因为还有很多与此样式无关的其他内容)

 .gunimage { display: inline-block; margin-left: auto; margin-right: auto; width: 15%; padding-left: 20px; } #images { text-align: center; } 
 <div id="images"> <img class="gunimage" border="0" alt="idk" src="gg.png" /></a> <p>this is text</p> <img class="gunimage" border="0" alt="idk" src="gg2.png" /></a> <p>this is also text</p> </div> 

This method uses HTML 5 figure and figcaption elements, and CSS 3 flexbox . 此方法使用HTML 5 figurefigcaption元素以及CSS 3 flexbox

 #images { display: flex; justify-content: center; } figure { text-align: center; } 
 <div id="images"> <figure> <img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""> <figcaption>this is text</figcaption> </figure> <figure> <img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""> <figcaption>this is also text</figcaption> </figure> </div> 

NOTE: Flexbox is supported by all major browsers, except IE 8 & 9 . 注意: 除了IE 8和9之外 ,所有主流浏览器都支持Flexbox。 Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes . 某些最新的浏览器版本(例如Safari 8和IE10)需要供应商前缀 For a quick way to add prefixes, use Autoprefixer . 要快速添加前缀,请使用Autoprefixer More details in this answer . 此答案中有更多详细信息。

Here is a solution using floats 这是使用浮子的解决方案

 .gunimage { display: inline-block; margin-left: auto; margin-right: auto; width: 15%; } .half { width:50%; float: left; } #images { text-align: center; width: 100%; } 
 <div id="images"> <div class="half"> <img class="gunimage" border="0" alt="idk" src="gg.png"> <p>this is text</p> </div> <div class="half"> <img class="gunimage" border="0" alt="idk" src="gg2.png"> <p>this is also text</p> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM