CSS中用table可以实现哪些布局,代码是什么
Admin 2022-07-13 群英技术资讯 473 次浏览
本文介绍了CSS 利用table实现五种常用布局的方法示例,分享给大家,具体如下:
布局一:
效果:
代码:
html:
<div class="header">header</div> <div class="main">main</div> <div class="footer">footer</div>
注意:div中要有内容,不然显示不出来
css:
body{ margin:0; padding:0; width:100%; min-height:100vh; display:table; text-align:center; } .header,.main,.footer{ display:table-row; } .header{ height:50px; background:tomato; } .main{ background:skyblue; } .footer{ height:50px; background:#9d70ff; }
布局二:
效果:
代码:
html:
<div class="header">header</div> <div class="main"> <div class="left">left</div> <div class="right">right</div> </div> <div class="footer">footer</div>
css:
body{ margin:0; padding:0; width:100%; min-height:100vh; display:table; text-align:center; } .header,.main,.footer{ display:table-row; } .header{ height:50px; background:tomato; } .main{ width:100%; display:table; height:calc(100vh - 100px); } .main .left{ width:300px; display:table-cell; background:#fcea96; } .main .right{ display:table-cell; background:skyblue; } .footer{ height:50px; background:#9d70ff; }
注意:.main的height属性中的100px是header和footer的高度之和
布局三:
效果:
代码:
html:
<div class="left">left</div> <div class="right"> <div class="header">header</div> <div class="main">main</div> <div class="footer">footer</div> </div>
css:
body{ margin:0; padding:0; min-height:100vh; display:table; text-align:center; } .left{ display:table-cell; width:200px; background:tomato; } .right{ display:table; width:calc(100vw - 200px); height:100vh; } .header,.main,.footer{ display:table-row; } .header{ height:50px; background:skyblue; } .main{ background:#fcea96; } .footer{ height:50px; background:#9d70ff; }
布局四(双栏布局,例子为左边固定,右边自适应):
效果:
代码:
html:
<div class="left">left</div> <div class="right">right</div>
css:
body{ margin:0; padding:0; width:100%; height:100vh; display:table; text-align:center; } .left,.right{ display:table-cell; } .left{ width:300px; background:tomato; } .right{ background:skyblue; }
布局五(三栏布局,例子为左边固定,右边固定,中间自适应):
效果:
代码:
html:
<div class="left">left</div> <div class="middle">middle</div> <div class="right">right</div>
css:
body{ margin:0; padding:0; width:100%; height:100vh; display:table; text-align:center; } .left,.middle,.right{ display:table-cell; } .left{ width:300px; background:tomato; } .middle{ background:#ffe69e; } .right{ width:200px; background:skyblue; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
将js中的对象格式化,并打印在html中functionwriteHtml(name,obj){varobjStr=JSON.stringify(obj,null,4);varhtml=objStr.replace(/\n/g,'<br>').replace(/\s/g,'&nbsp');document.write(n
这篇文章主要介绍了HTML5开发动态音频图的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
前端项目中flex文本溢出的情况有哪些解决方案?实际项目的操作过程或是学习过程中,不少人都会遇到这样的问题,接下来就让小编带大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
篇文章给大家分享的是DIV自适应高度自动补充剩余高度的实现。小编觉得挺实用的,因此分享给大家做个参考,文中示例代码介绍的非常详细,感兴趣的朋友接下来一起跟随小编看看吧。
一般来说,给表格加边框都会出现不同的问题,以下是给表格加边框后展现比较好的方式<style>table,tabletrth,tabletrtd{border:1pxsolid#0094ff;}table{width:200px;min-height:25px;line-height:25px;text-alig
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008