html - 垂直对齐两个 div 中的内容

标签 html css

我有两个相邻的 div。
左边的 div 包含一个 Logo ,右边的 div 包含一行链接(菜单)

我想将右侧 div 中的菜单与左侧 div 中的 Logo 垂直对齐。
这是代码:

<div id="header">
    <div class="logo">
        image.jpg
    </div>
    <div class="navigation">
    link 1  | link 2 | link 3
    </div>
</div>

CSS:

#header{
padding: 3% 0 2% 0;
width: 100%;
display:table;
}

.logo{
display:inline-block;
max-width:19%;  
text-align:left;
}

.navigation{
display:inline-block;
text-align:right;
width:81%;
}

最佳答案

Flexbox应该做的伎俩。看这个fiddle .

.header {
    display: flex;
    flex-direction: row;
    align-items: center;
}

.logo {
    flex: 0 0 20%;
}

.navigation {
    flex: 0 0 80%;
}

关于html - 垂直对齐两个 div 中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33691449/

相关文章:

html - 为响应式网站调整图像大小;不调整大小

html - 滚动 CSS 时图像内容全屏

javascript - Reactjs 安装指南中的 Hello-world 不起作用

javascript - 多个下拉值不会显示在新的 HTML 页面中

html - 高度超过浏览器高度的 100%

html - CSS 自动调整网格元素大小

jquery - 使用 CSS 或 jQuery 去除列的侧边距

html - 悬停在 anchor 上不会停留在绝对定位的位置

css - 如何为根目录中的文件夹创建路径?

CSS 似乎无法将高度设置为父容器的 100%