html - 居中对齐 3 个内联的 div 标签

标签 html css alignment

我在一个父 div 中有 3 个 div 标签。我想将所有东西都居中对齐。

div-1 - Left Arrow link to prev image set.
div-2 - It will have multiple images.
div-3 - Right Arrow link to next image set.

我正在做以下事情:

#container { text-align: center; }
#div-1 { float: left; }
#div-2 { display: inline; }
#div-3 { float: right; }

有了这个图像根据需要显示在中心。但是左箭头和右箭头显示在屏幕的最左边和最右边。

如何在图像之外显示它们?

最佳答案

我会使用 display: inline-block;像这样:

#container{ 
    text-align: center;
}
#div-1, #div-2, #div-3{
    display: inline-block; 
}

然后,如果您还想将它们垂直居中,您可以添加 vertical-align: center;给你的 child div。

关于html - 居中对齐 3 个内联的 div 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20031092/

相关文章:

html - i 标签的差异行为 IE/Chrome

java - 使用 CSS/Java 显示图像而不是按钮框架

javascript - 仅在可滚动时才向 div 添加边框

html - 如何将页脚移动到页面底部?

html - 悬停时的 css 交换图像无法正常工作 - 悬停图像显示在主图像后面

css - 圆形和文本对齐 CSS3

html - 为什么 tabindex ='-1' 会阻止键盘

css - Sublime Text 3 中的 Sass + CSS3 + CSS Comb

css - 如何让按钮文本在 IE 中顶部对齐?

c - 结构的内存对齐