美文网首页
2018-06-24

2018-06-24

作者: 铁杵磨针 | 来源:发表于2018-06-24 08:59 被阅读0次

    css 网页布局学习心得

    1.左右布局

    <div class="container"> 
            <div class="left" style="background: red;height: 300px;float:left;width: 30%">左右布局-左页
            </div>
            <div class="right" style="background: blue;height: 300px;float: left;width: 70%">左右布局-右页    
            </div>
        </div>
    
    image.png

    2.左中右布局

    <div class="container"> 
            <div class="left" style="background: red;height: 300px;float:left;width: 20%">左中右布局-左页
            </div>
            <div class="left" style="background: green;height: 300px;float:left;width: 60%">左中右布局-中页
            </div>
            <div class="right" style="background: blue;height: 300px;float: left;width: 20%">左右布局-右页    
            </div>
        </div>
    
    image.png

    3.水平布局

    <div class="container" style="margin-right:auto;margin-left:auto;border: 1px solid red; width: 800px;height: 200px;" >  
                <div class="left" style="background: red;height: 300px;float:left;width: 30%">水平居中-左页
                </div>
                <div class="right" style="background: blue;height: 300px;float: left;width: 70%">水平居中-右页    
                </div>  
        </div>
    
    image.png

    4.垂直布局

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title> 垂直居中</title>
    </head>
    <body>
        <div style="width: 800px;height: 200px;background: blue;position: absolute;top:50%;left:50%;margin-top: -100px;margin-left: -400px;
        "   >垂直居中</div>
    </body>
    </html>
    
    image.png

    5.其他小技巧

    在浮动布局时,子元素加folat属性,父元素必须加cleanfix属性,以清除浮动影响。
    在网页布局时,尽量模块化,各个div不要相互耦合,这样做出的网页好维护,bug少。

    相关文章

      网友评论

          本文标题:2018-06-24

          本文链接:https://www.haomeiwen.com/subject/ahdjyftx.html