Home > Web Front-end > HTML Tutorial > css中左侧固定,右侧自适应_html/css_WEB-ITnose

css中左侧固定,右侧自适应_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:36:16
Original
1273 people have browsed it

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

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

1.只告诉你宽度;       2.只告诉你高度;       3.宽度和高度告诉你;(我总结了可能的3种方式) HTML:

<div class="container"><div class="left">左侧固定宽度200px</div><div class="right">右侧自适应</div></div>
Copy after login

No1:方法一

.container{width: 100%; }.left{color:red; background: gray; float: left; height: 100px}//左侧的div.right{color:red; background: blue; margin-left: -200px;}//右侧的div
Copy after login

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}
Copy after login

       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; }
Copy after login

No4:方法四

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

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 ;}
Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template