[英]How to center 2 images within a single DIV
I have a DIV tag that contains 2 tags. 我有一个包含2个标签的DIV标签。 I want these figures to center themselves within the DIV, which is supposed to be centering itself within the middle of the page.
我希望这些图形在DIV中居中,而DIV应该在页面中间居中。 How do I do this?
我该怎么做呢?
HTML: HTML:
<div class="images-captions">
<figure><img src="images/Prop Pics/From Mike B aka StratosDadRI/intial-blueprinting_thumb.jpg" alt="Intial Blueprinting"><figcaption>After intinal blueprint</figcaption></figure>
<figure><img src="images/Prop Pics/From Mike B aka StratosDadRI/after-damage_thumb.jpg" alt="After Damage"><figcaption>After damage</figcaption></figure>
</div>
CSS: CSS:
.images-captions { width: 600px; margin: 0 auto; }
.images-captions figure { float: left; width: 250px; padding: 10px;}
.images-captions figcaption { text-align: center; font-style: italic; }
This case I would solve like this: 这种情况下,我会这样解决:
CSS CSS
.images-captions {
width: 600px;
margin: 0 auto;
text-align: center;
}
.images-captions figure {
display: inline-block;
width: 200px;
margin: 0;
padding: 10px;
}
.images-captions figcaption {
font-style: italic;
}
Demo 演示版
You can solve it like this: 您可以这样解决:
CSS CSS
.images-captions {
width: 600px;
margin: 0 auto;
text-align: center;
}
.images-captions figure {
width: 200px;
margin: 0 auto;
}
.images-captions figcaption {
font-style: italic;
}
Demo 演示版
You can solve it by adding the text-align to the figure 您可以通过在文本上添加文本对齐来解决
.images-captions figure { float: left; width: 250px; padding: 10px;text-align:center}
.images-captions figcaption { font-style: italic; }
For understanding: 为了理解:
You want to align the text in the parent conatainer. 您要在父容器中对齐文本。 So you have to add the attribute to the parent element and not the element itself
因此,您必须将属性添加到父元素,而不是元素本身
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.