首页 > Web开发 > 详细

css中左侧固定,右侧自适应

时间:2015-09-28 09:51:30      阅读:274      评论:0      收藏:0      [点我收藏+]

谈谈我开始出来工作时候的一道面试题吧

       当初我记得在太平洋网络面试的时候,面试官给我出了这么一道题: 有一个外层的div 中间有左右两个div 要求左侧的div

        1.只告诉你宽度;       2.只告诉你高度;       3.宽度和高度告诉你;(我总结了可能的3种方式)
        HTML:
<div class="container">
<div class="left">左侧固定宽度200px</div>
<div class="right">右侧自适应</div>
</div>
        No1:方法一
.container{width: 100%; }
.left{color:red; background: gray; float: left; height: 100px}//左侧的div
.right{color:red; background: blue; margin-left: -200px;}//右侧的div

                    No2:方法二

.container{width: 100%;}
.left {width:200px; background:#fcc; position:absolute; left:0 ;z-index:1 }
.right {width:100%; background:#ccc; position:absolute; left:0}

       No3:方法三

.container{width:100%}
.left { background-color: green; float: left; width: 200px; margin-right: -100%; }
.right { float: left; width: 100%;margin-left: 200px; background-color:blue; }

                     No4:方法四

.container{width:100%}
.left{position: absolute; top:0; left:0; width:200px; background: #ff0;}
.right{ margin-left: 200px; background: #f0f;}

                     No5:方法5

.container{width:100%}
.left{ position: absolute; top:0 ; left:0 ;width:200px; background:blue;}
.right{ position: absolute; top:0 ; left:200px; width: 100% ; rigth:0;background:red ;}

其实还有很多方法可以实现(其它的我就懒得写了),所谓条条大路通罗马,咳咳,不喜勿喷

css中左侧固定,右侧自适应

原文:http://www.cnblogs.com/Expando/p/4843230.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!