如何垂直对齐浮动图像

时间:2017-10-05 21:11:13

标签: html css image vertical-alignment floating

我有这个漂浮的图像,我想把它放在flex-navbar的左边。布局应该是响应的,图像垂直对齐到中间(垂直对齐:中间;不起作用)。 提前谢谢!

https://jsfiddle.net/wonrpfsc/

<div class="container">
        <a href="#"><img id="logo" src="http://brandmark.io/logo-rank/random/apple.png" alt=""/></a>
    <div id="navbar">
        <a href="#">Home</a>
        <a href="#">About U</a>
        <a href="#">Our Service</a>
        <a href="#">Our Products</a>
        <a href="#">Contac</a>
    </div>
</div>


#navbar {
    display: flex;
}

#navbar a {
    flex: 1 1 0;
    text-align: center;
    padding: 10px;
    border: 1px solid black;
}

#logo {
    width: 10vw;
    height: 10vw;
    float: left;
    vertical-align: middle;
}

1 个答案:

答案 0 :(得分:1)

您可以尝试将徽标移动到导航栏div中,如下所示:

'<div class="container">
    <div id="navbar">
       <a href="#"><img id="logo" src="http://brandmark.io/logo-rank/random/apple.png" alt=""/></a>
        <a href="#">Home</a>
        <a href="#">About U</a>
        <a href="#">Our Service</a>
        <a href="#">Our Products</a>
        <a href="#">Contac</a>
    </div>
</div>'

并像这样更改CSS:

#navbar {
    display: flex;
    justify-content: center;
    align-items: center;
}