html - 动态添加 DIVS

标签 html css

我正在尝试动态添加子 div,这会自动调整其父 div 的大小,但我的 CSS 无法正确呈现它们。代码如下

HTML

<head>
        <title>Dealer Services Hub</title>    
    </head>    
    <body>
        <div id="wrapper"> 
            <div id="header">
             </div>
            </div>

            <div id="body">

                <div id = "maindiv">
                    <div class = 'maindivs'>Sales/Credit</div>
                    <div class = 'maindivs'>Finance</div>
                    <div class = 'maindivs'>Compliance/Audit</div>
                    <div class = 'maindivs'>Admin</div>
                    <div class = 'maindivs'>Reporting</div>
                    <div class = 'maindivs'>EOT</div>
                    <div class = 'maindivs'>Test</div>

                </div>

                <div id = "sidebardiv">

                     <div class = 'sidebardivs' div id = 'recentsdiv'><div id = 'recentlinkstitle'>Frequent Views</div></div>
                  <div class = 'sidebardivs' div id ='dealercommentsdiv'>Dealer Comments</div>
                  <div class = 'sidebardivs'>Dealers</div>                    

                </div>

            </div>

    <!--Footer Div-->
         <div id="footer">
             <div>
                 <span>USBNet</span>
             </div>

             <div>
                <span>Best In Us</span>
             </div>

             <div>
                <span>Directory</span>
             </div>


         </div>

        </div>



</body>

CSS

body{
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}

#body{
    width: 100%;
    height: 100%;
    float: left;
    color:#0C2074;
}

h2{
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;  
}

#wrapper {
    width:1400px;
    margin: 0;
    padding: 0; 
    height: 100%;
    overflow:auto; 
}

#header{
    width: 1320px;
    height: 100px;
    float: left;
    background: #0C2074;
    margin: 0 auto;
}

#maindiv{
    width:1000px;
    height:100%;
    float: left;
    color:#0C2074;
    overflow:hidden;
}

.maindivs{
    width:300px;
    height: 220px;
    background: #67B2E8;
    box-shadow: 10px 10px 8px #888888;
    text-align: center;
    float: left;
    margin-top: 20px; 
    margin-left: 20px;
    cursor:pointer;
    border-radius: 10px;
    color:#0C2074;
}


#sidebardiv{
    width:300px;
    height:100%;
    float: left;
    border-left: 1px solid #5a5a5a;
    overflow:hidden;  
}


.sidebardivs{
    width:90%;
    height: 220px;
    border: 1px solid #000000;
    background: #e5e5e5;
    color:#0C2074;
    margin-top: 20px; 
    margin-left: 20px;
    border-radius: 10px;
}

#recentsdiv{
    font-size: 95%;    
}

#dealercommentsdiv{
    text-align: center;
    float: left;
    margin-bottom: 20px;
    cursor:pointer;
}

#footer{
    width: 1320px;
    height:40px;
    float: left;
    background: #0C2074;
    clear: both;
    color:#FFF;
}

#footer div{
    width:33.33%;
    height: 100%;  
    text-align: center;
    float: left;
    margin: auto;
    padding-top: 5px;
    padding-right: 5px;;
    padding-bottom: 5px;
    padding-left: 5px;
    border-left: 1px solid #67B2E8;
    border-right: 1px solid #67B2E8;
    font-size: 120%;
    box-sizing: border-box;    
}

附加的 div 是父级 'maindiv' 的 'Test' 和父级 'sidediv' 的 'Dealers' 结果是 'Test' div 似乎在其底部和 'Dealers' 之间的空间被切断div 是多余的

最佳答案

现在好点了吗?:

body{
    font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}

#body{
    width: 100%;
    height: 100%;
    float: left;
    color:#0C2074;
}

#wrapper {
    width:100%;
    margin: 0;
    padding: 0; 
    height: 100%;
    overflow:auto; 
}

#header{
    width: 100%;
    height: 100px;
    float: left;
    background: #0C2074;
    margin: 0 auto;
}

#maindiv{
    width:80%;
    height:100%;
    float: left;
    color:#0C2074;
    overflow:hidden;
    padding-bottom: 35px;
}

.maindivs{
    width:30%;
    height: 210px;
    background: #67B2E8;
    box-shadow: 7px 7px 8px #666;
    text-align: center;
    float: left;
    padding-top: 10px;
    margin-top: 30px; 
    margin-left: 2.5%;
    cursor:pointer;
    border-radius: 7px;
    color:#0C2074;
}


#sidebardiv{
    width:19%;
    height:100%;
    float: left;
    border-left: 1px solid #5a5a5a;
    overflow:hidden;  
}


.sidebardivs{
    width:80%;
    height: 210px;
    padding-top: 10px;
    border: 1px solid #000000;
    background: #e5e5e5;
    color:#0C2074;
    margin-top: 30px; 
    margin-left: 20px;
    border-radius: 7px;
    text-align:center;
}

#recentsdiv{
    font-size: 95%;    
}

#dealercommentsdiv{
    text-align: center;
    float: left;
    margin-bottom: 20px;
    cursor:pointer;
}

#footer{
    width: 100%;
    height:40px;
    background: #0C2074;
    clear: both;
    color:#FFF;
    text-align:center;
}

#footer div{
    width:30%;
  	height: 32px;
    display: inline-block;
    margin: auto;
    padding-top:8px;
    padding-right: 1%;
    padding-left: 1%;
    border-left: 1px solid #67B2E8;
    border-right: 1px solid #67B2E8;
    font-size: 22px;
}
<head>
<title>Dealer Services Hub</title>    
</head>    
    <body>
        <div id="wrapper"> 
        <div id="header">
        </div>
            </div>

            <div id="body">

                <div id="maindiv">
                    <div class = 'maindivs'>Sales/Credit</div>
                    <div class = 'maindivs'>Finance</div>
                    <div class = 'maindivs'>Compliance/Audit</div>
                    <div class = 'maindivs'>Admin</div>
                    <div class = 'maindivs'>Reporting</div>
                    <div class = 'maindivs'>EOT</div>
                    <div class = 'maindivs'>Test</div>

                </div>

                <div id = "sidebardiv">

                  <div class ='sidebardivs' id = 'recentsdiv'><div id = 'recentlinkstitle'>Frequent Views</div></div>
                  <div class ='sidebardivs' id ='dealercommentsdiv'>Dealer Comments</div>
                  <div class = 'sidebardivs'>Dealers</div>                    

                </div>

            </div>

    <!--Footer Div-->
         <div id="footer">
             <div>
                 <span>USBNet</span>
             </div>

             <div>
                <span>Best In Us</span>
             </div>

             <div>
                <span>Directory</span>
             </div>


         </div>

        </div>



</body>

关于html - 动态添加 DIVS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41176564/

相关文章:

html - 将包装器拉伸(stretch)到其内容的全宽

html - CSS Class里面的背景图片到<div>

javascript - 基于组件变量的 ngx-datatable 动态单元格样式

html - 当窗口高度降低时如何防止页脚移出上面的元素

html - 创建一个 css 模板,无边距地覆盖整个页面,即使内容几乎是空的

html -::在将内容放入无花果标题之前,有什么办法可以避免这种情况吗?

php - 不将值从 PHP 传输到 echo

javascript - 内容扩展时图像错位

javascript - 如何在 <div> 后面的 <div> 上锁定滚动

javascript - 高度等于动态宽度(CSS 流体布局)