html - 如何实现 2 列等高的布局,第一列有 1 个元素,第二列有 2 个元素,没有 float ?

标签 html css layout stylesheet

我正在尝试为左侧栏中有 Logo 、右侧栏中有旋转图像横幅和顶级导航的网站制作标题,但不使用 float 。我在这里做错了什么?

这是我希望的样子:

enter image description here

这是我的 HTML:

<!doctype html>
<head>
<title></title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="header">
    <div id="logo"><p>Logo</p></div>
    <div id="right">    
        <div id="rotator"><p>Rotator</p></div>
        <div id="navigation"><p>Navigation</p></div>
    </div>
</div>
</body>
</html>

这是我的 CSS:

#header{
    width: 1024px;
    margin-left: auto;
    margin-right: auto;
    background-color: yellow;
    top: 10px;
    font-size: 0px;
}
#logo{
    display: inline-block;
    background-color: red;
    width: 306px;
    height: 192px;
    font-size: 0px;
}
#right{
    display: inline-block;
    background-color: black;
    width: 718px;
    height: 192px;
    font-size: 0px;
}
#rotator{
    display: block;
    background-color: green;
    width: 718px;
    height: 132px;
}
#navigation{
    display: block;
    background-color: blue;
    width: 718px;
    height: 60px;
}
p{
    font-size: 24px;
    margin:0;
    padding: 0;
}

这是它最终的样子: enter image description here

最佳答案

尝试将 vertical-align: top; 放在 Logo 和右边的 div 上

Here's the fiddle

#logo{
display: inline-block;
background-color: red;
width: 306px;
height: 192px;
font-size: 0px;
vertical-align: top;

#right{
display: inline-block;
background-color: black;
width: 718px;
height: 192px;
font-size: 0px;
vertical-align: top;

关于html - 如何实现 2 列等高的布局,第一列有 1 个元素,第二列有 2 个元素,没有 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14647722/

相关文章:

javascript - 有没有一种方法可以使用 javascript 仅合并表中的特定列

html - css 在 gmail 中未完全显示

html - 如何在两列内显示容器?

html - 如何在 HTML 5 中创建带有简单边框的表格

html - float Div 在 Zoom 上突然出现

layout - Cadence Virtuoso Layout L 虚拟对象

html - 需要帮助让 oracle "SORT BY"以我想要的方式工作

html - 如何指定从哪个样式表调用类

css - ASP.Net GridView 样式 - 不可见的单元格衬里

html - Stick footer 无 CSS 教程,享受乐趣