Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的网站上的 CSS 样式有点困难,目前我有一排图像,我想沿着我的页面水平对齐。但刚才它在一行中垂直显示它们,我不知道为什么。所有的图像都存储在一个数组中,只是让它们排列起来就是问题所在。这是我的代码:
.img{ float:left; width:120px; margin:auto; margin-left:10px; padding:5px; }
您应该将 . 添加到您的样式display:inline-block中。该inline-block值使您的 .img 不会在末尾显示换行符。
display:inline-block
inline-block
默认情况下,图像是display: inline. 这意味着如果容器中有空间,默认情况下它们不会水平清除其他元素。调整图像元素父容器的宽度:示例
display: inline
如果您希望图像水平扩展而与容器宽度display: table-cell无关,请在包装每个图像元素的 div 中使用样式(css):示例
display: table-cell