浅析CSS等高布局的6种方式

2020-05-06 09:20:25易采站长站整理

        <p>center</p>  
    </div>             
    <div class="right" style="background-color: lightgreen;">  
        <p>right</p>  
    </div>           
</div>  

js  

当子元素高度不同时,进行js判断,增加较低子元素的padding-bottom,使得各个子元素实现等高效果

CSS Code复制内容到剪贴板

<style>   
body,p{margin: 0;}   
.parent{overflow: hidden;}   
.left,.center,.rightright{   
    float: left;   
    width: 25%;   
}       
.center{   
    width: 50%;   
    padding: 0 20px;   
    background-clip: content-box;   
    box-sizing: border-box;   
}   
</style>  

XML/HTML Code复制内容到剪贴板

<div class="parent" id="parent" style="background-color: lightgrey;">  
    <div class="left" style="background-color: lightblue;">  
        <p>left</p>  
    </div>     
    <div class="center" style="background-color: pink;">  
        <p>center</p>  
        <p>center</p>  
    </div>             
    <div class="right" style="background-color: lightgreen;">  
        <p>right</p>  
    </div>           
</div>  

JavaScript Code复制内容到剪贴板

<script>   
function getCSS(obj,style){   
    if(window.getComputedStyle){   
        return getComputedStyle(obj)[style];