对齐一个float:left div to center? [英] Aligning a float:left div to center?
问题描述
我想让一组图片在整个网页上水平显示。每个图像下面有一些链接,所以我需要在每个图像/链接组的一个容器。
I want to have a group of images display horizontally across the page. Each image has a few link below it so I need to put a container around each image/link-group.
最近我已经得到了我想要的是把它们在divs中float:left。问题是我想要容器对齐中心不左。如何实现这一点。
The closest I have gotten to what I want is putting them in divs that float:left. The problem is I want the containers to align center not left. How can I achieve this.
推荐答案
使用 display:inline-block;
而不是float
use display:inline-block;
instead of float
你不能将浮动对中,但是inline-blocks中心如同他们是文本,所以在行的外部整体容器 - 你会为每个图像/ caption容器设置 text-align:center;
(这将是 inline-block;
),如果需要
you can't centre floats, but inline-blocks centre as if they were text, so on the outer overall container of your "row" - you would set text-align: center;
then for each image/caption container (it's those which would be inline-block;
) you can re-align the text to left if you require
这篇关于对齐一个float:left div to center?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!