html - 水平对齐 3 个嵌套的 div

标签 html css wordpress

我在 wordpress 工作,对看似简单的事情感到有点沮丧。我正在尝试构建一组 3 个框,每个框内都有嵌套的 div。

最终产品应该是这样的:

我可以单独构建框,没问题,但是当我尝试用内部嵌套的 div 显示它们时,它们会垂直对齐。

这是我目前使用的代码:

    #bannercontainer { 
    text-align: center;
    width: 100%;
    align: center;
}
#bcdiv1 {   
    position: relative;
    width: 33%; 
}
#bcdiv2 { 
    position: relative;
    width: 34%; 
}
#bcdiv3 { 
    position: relative;
    float: right;
    width: 33%; 
}
#bannerbox {
    border: 2px solid;
    border-radius: 10px;
    background-color: dbdbdb;
    width: 325px;
    height: 150px;
    margin: 5px;
}
#bbdivtop {
border: 2px solid;
    position: relative;
    float: top;
    height: 50px;
    width: 100%;
}
#bbdivleft {
border: 2px solid;  
position: relative;
    float: left;
    width:50px;
    height: 80px;
}
#bbdivright {
border: 2px solid;
    position: relative;
    float: right;
    height: 80px;
}
#bbdivbottom {
border: 2px solid;
    position: absolute;
    bottom: 0;
    height: 20px;
    width: 100%;
    float: bottom;
}

和 html

<div id="bannercontainer">

            <div id="bannerbox">
                <div id="bbdivtop">
                test
                </div>
                <div id="bbdivleft">
                test
                </div>
                <div id="bbdivright">
                test
                </div>
                <div id="bbdivbottom">
                test
                </div>
            </div>
            <div id="bannerbox">
                <div id="bbdivtop">
                test
                </div>
                <div id="bbdivleft">
                test
                </div>
                <div id="bbdivright">
                test
                </div>
                <div id="bbdivbottom">
                test
                </div>
            </div>
            <div id="bannerbox">
                <div id="bbdivtop">
                test
                </div>
                <div id="bbdivleft">
                test
                </div>
                <div id="bbdivright">
                test
                </div>
                <div id="bbdivbottom">
                test
                </div>
            </div>
        </div>

最佳答案

为主 div with id bannerbox 添加 float:left 并将 width 更改为 percentage。尝试:

#bannerbox {
    border: 2px solid;
    border-radius: 10px;
    background-color: dbdbdb;
    width: 30%;
    height: 150px;
    margin: 5px;
    float:left;
}

DEMO FIDDLE

关于html - 水平对齐 3 个嵌套的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19231842/

相关文章:

html - Chrome 在图像上插入框阴影,过渡不起作用

javascript - 在重力形式计算中使用指数

html - 将 UL 置于父级的中心并忽略其他 float UL

javascript - 如何删除 html 表格中连续单元格的类

javascript - 仅选中一张表中的所有复选框

html - HTML 5 验证是否物有所值?

html - 用网站标题中的文本替换 Logo 图像

html - 使用 css 悬停时 td 标签上的边框移动整个表格

jquery - :not(. classA, .classB, .classC) 的相反选择器 for a (X and (A or B or C)) selector

WordPress - 分页帖子的每一页都显示相同的帖子