简体   繁体   English

如何使此图像与文本居中对齐?

[英]How to center align this image with the text?

I am trying to center the rounded image with the text, however I can not succeed to it. 我试图将舍入后的图像与文本居中,但是我无法成功实现。

What should I change to my code to do it? 我该如何更改我的代码?

https://jsfiddle.net/zxwz5739/ https://jsfiddle.net/zxwz5739/

<div class="col-sm-6">
    <div class="team-1-member">
        <div class="round">
            <center>
                <img alt="Team Member" src="http://i.imgur.com/qIKR0Qt.gif">
            </center>
        </div>
            <h2>John Doe</h2>

    </div>
</div>

.team-1-member {
    text-align: center;
    margin-top: 48px;
}
.round {
    border-radius: 50%;
    overflow: hidden;
    width: 150px;
    height: 150px;
    margin-bottom: 10px;
}
.round img {
    display: block;
    min-width: 100%;
    min-height: 100%;
}
.team-1 h2 {
    margin-bottom: 8px;
}

到.round添加:display:inline-block;

For .round, change your margin-bottom: 10px; 对于.round,更改您的下margin-bottom: 10px; to margin: 0 auto 10px auto; margin: 0 auto 10px auto; .

I'd also suggest getting rid of your <center> tags. 我还建议您摆脱<center>标签。 They're technically not supposed to be used anymore. 从技术上讲,不应再使用它们。

You can basically remove your outer div and center and change the image itself to display: inline-block . 您基本上可以删除外部divcenter并将图像本身更改为display: inline-block

New HTML code: 新的HTML代码:

<div class="col-sm-6">
    <div class="team-1-member">
        <img alt="Team Member" src="http://i.imgur.com/qIKR0Qt.gif" class="round" />
        <h2>John Doe</h2>
    </div>
</div>

New CSS code: 新的CSS代码:

.team-1-member {
    text-align: center;
    margin-top: 48px;
}

.round {
    border-radius: 50%;
    width:150px;
    height:150px;
    display: inline-block;
}

.team-1 h2 {
    margin-bottom: 8px;
}

Result as jsfiddle . 结果为jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM