温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

DIV+CSS如何实现三列布局

发布时间:2021-09-14 14:45:39 来源:亿速云 阅读:177 作者:小新 栏目:web开发

这篇文章将为大家详细讲解有关DIV+CSS如何实现三列布局,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

1、宽度自适应三列布局

  三列布局的原理和两列布局的原理是一样的,只不过多了一列,只需给宽度自适应两列布局中间再加一列,然后重新计算三列的宽度,就实现了宽度自适应的三列布局。

  同样的道理,更多列的布局,其实和两列、三列的布局模式是一样的。

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="UTF-8">  
    <title>三列布局</title>  
<style>  
*{margin:0;padding:0;}   
#herder{   
    height:50px;   
    background:blue;   
}   
#main{   
    width:100%;   
    overflow:hidden;   
}   
#main .main-left{   
    width:25%;   
    height:800px;   
    background:red;   
    float:left;   
}   
#main .main-center{   
    width:50%;   
    height:800px;   
    background:lightgreen;   
    float:left;   
}   
#main .main-right{   
    width:25%;   
    height:800px;   
    background:pink;   
    float:right;   
}   
#footer{   
    height:50px;   
    background:gray;   
}   
</style>  
</head>  
<body>  
<div id="herder">页头</div>  
<div id="main">  
    <div class="main-left">左列</div>  
    <div class="main-center">中间</div>  
    <div class="main-right">右列</div>  
</div>  
<div id="footer">页脚</div>  
</body>  
</html>

2、左右两列固定宽度,中间内容宽度自适应

  要想实现左右两列固定宽度,中间宽度自适应的布局,那么使用浮动就做不到了,使用浮动之后页面就乱了,必须使用绝对定位来将三列固定在一行。

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="UTF-8">  
    <title>两边固定中间自适应布局</title>  
<style>  
*{margin:0;padding:0;}   
#herder{   
    height:50px;   
    background:blue;   
}   
#main{   
    width:100%;   
    position:relative;   
}   
#main .main-left{   
    width:200px;   
    height:800px;   
    background:red;   
    position:absolute;   
    left:0;   
    top:0;   
}   
#main .main-center{   
    height:800px;   
    background:lightgreen;   
    margin:0 310px 0 210px;   
}   
#main .main-right{   
    width:300px;   
    height:800px;   
    background:pink;   
    position:absolute;   
    right:0;   
    top:0;   
}   
#footer{   
    height:50px;   
    background:gray;   
}   
</style>  
</head>  
<body>  
<div id="herder">页头</div>  
<div id="main">  
    <div class="main-left">左列</div>  
    <div class="main-center">设计网页的第一步就是设计版面布局,搭建网站结构,网页排版的合理性,在一定程度上也影响着网站整体的布局以及后期的优化。一个好的网站形象能更容易地吸引用户、留住用户。因此,网站首页第一屏的排版非常重要,很多时候能决定用户的去与留。</div>  
    <div class="main-right">右列</div>  
</div>  
<div id="footer">页脚</div>  
</body>  
</html>

关于“DIV+CSS如何实现三列布局”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI