会员中心
用户名:    密码:    验证码:      免费注册会员

jquery手册   CSS2手册       请关注健康

CSSer > 客户端开发 > web标准与前台开发 > 固定右栏宽度, 左栏内容先出现同时自适应宽度的布局

来源:lab.loaoao.com 作者: 发布时间:2007-03-18
雅虎收藏夹 百度收藏 Google书签 Yahoo书签 新浪ViVi 搜狐网摘 365Key网摘 天极网摘 diglog 和讯网摘 POCO网摘 YouNote网摘 博拉网 天下图摘 Del.icio.us digg reddit spurl BlinkList blogmarks

以下为引用的内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>固定右栏宽度, 左栏内容先出现同时自适应宽度的布局</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="KEYWords" content="fixed,css,xhtml,effect" />
<meta name="DEscription" content="固定右栏宽度, 左栏内容先出现同时自适应宽度 " />
<meta name="author" content="aoao" />
<meta content="all" name="robots" />
<style type="text/css">

body{
font-family:Verdana, Arial, Helvetica, sans-serif;
min-width:620px;
margin:0;
padding:0;
}

#wrapper{
float:left;
display:inline;
margin:0 30px;
background-color:#ccc;
}
#header,#footer{
clear:both;
padding:10px;
text-align:center;
}
#left{
float:left;
width:100%;
margin:0 0 0 -200px;
}
#innerLeft{
margin:0 0 0 200px;
background-color:#efefef;
}
#right{
float:left;
width:200px;
background-color:#ddd;
}
.inner {
padding:2px 12px;
}
p{ line-height:1.6em}
</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>固定右栏宽度, 左栏内容先出现同时自适应宽度的布局</h1>
</div>
<div id="left">
<div id="innerLeft" class="inner">

<h2>工作原理</h2>
<p>#wrapper必须触发hasLayout,不然有时里面的内容会浮得怪怪的,我直接用float的,可以用其他方式。其实如果只是要做到这个例子要的效果连#wrapper都可以不要。<br />
#left定义100%宽度并利用margin:0 0 0 -200px把左边整块放在偏移入左边200px处,再利用#innerLeft的margin:0 0 0 200px再把内容撑出来,<br />
#right只是简单的浮动,#innerRight米多大作用,只是习惯性保留着,除了可以让我们的控制更简单点,还可以为下次改变布局可保持结构不变。</p>
<p>除了可以固定右边也可以固定左边,有空的朋友可以尝试一下</p>
<h2>存在问题</h2>
<ul>
<li>IE7以下版本的IE浏览器无min-width,拉太小会很难看。下篇文章再解决</li>
</ul>
</div>
</div>

<div id="right">
<div id="innerRight" class="inner">
<p>这只是个简单的例子,希望对初学CSS布局的朋友有帮助。</p>
<p>基本还有很多功能可以写进来,怕写得太乱了,还是等下一篇,好骗点流量。</p>
</div>
</div>
</body>
</html>


共2页: 上一页 [1] 2 下一页

相关文章