css - 一行div内的图像对齐

标签 css alignment

我有一排 div,我希望图像在垂直和水平方向居中。

<div id="treatments-wrapper">
                <div class="heading">
                    <h2>Our Treatments</h2>
                </div>
                <div class="treatments-logo">
                    <a href="#"><img src="img/nouveau-logo.png" alt="nouveau logo"></a>
                </div>
                <div class="treatments-logo">
                    <a href="#"><img src="img/nouveau-logo.png" alt="nouveau logo"></a>
                </div>
                <div class="treatments-logo">
                    <a href="#"><img src="img/nouveau-logo.png" alt="nouveau logo"></a>
                </div>
            </div><!--treatments-wrapper-->




 #treatments-wrapper {
    width:960px;
    height:100px;
    float: left;
    margin: 10px 0;
    border-bottom: #373839 solid 10px;
}

.treatments-logo {
    width: auto;
    height: 60px;
    float: left;
    margin: 0 8px;
}

.treatments-logo img {
    display: block;
    margin: auto;
}

.heading {
    width:960px;
    height: 40px;
    background-color: #373839;
    float: left;
    margin:
}

这里是jsfiddle

在这个例子中,我使用了同一张图片 3 次,但它将是一排不同的 Logo ,所有 Logo 的高度和宽度都不同。谁能建议我尝试一下?

最佳答案

尝试显示:表格单元格;垂直对齐:中间;

.treatments-logo {
    width: 1%;
    display:table-cell;
    height: 60px;
    vertical-align:middle;
}

关于css - 一行div内的图像对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20569955/

相关文章:

c++ - alignof运算符有什么用?

c++ 解决方案在 leetcode 上失败,地址未对齐错误,但在 Visual Studio 中运行

css - currentColor 似乎在 Safari 中得到 "stuck"

html - 如何为 Weather.com 等拼写错误的文本设置样式(虚线下划线而不是波浪线)

javascript - Javascript : Scale and transition after 的 Css3 动画

javascript - 子 div 单击事件的意外行为

css - 左对齐

ios - 在 iOS UIAlertController 中,我们可以左对齐 UIAlertAction 的文本吗

html - CSS - 在 Wordpress 中并排显示图像

html - 使用 CSS 选择类