特点是中间栏和父容器设置了最大和最小宽度,另外左右栏随屏幕固定,但其左和右属性继承父容器,上和下属性相对于浏览器显示区的上下。左栏设置超出高度时出现上下滚动条,宽度固定,不出现左右滚动条。

使用了一点jQuery,因为position:fixed会破坏父容器相对布局,虽然left可以继承,但right不能继承。

代码:

   
   
   
   
  1. "javascript"
  2. $(document).ready(function(){ 
  3.     var rightFix = ($(window).width()-$("div#topic-c").width())/2; 
  4.     $("div#topic-right").css("right",rightFix+"px"); 
  5. }); 
  6.  

 

   
   
   
   
  1. @charset "utf-8"
  2. /* CSS Document */ 
  3.  
  4. body{} 
  5.  
  6. #topic-c{ 
  7.     max-width:1500px
  8.     min-width:960px
  9.     margin:0 auto 20px auto
  10.     border:1px solid #33C
  11.     overflow:auto
  12.  
  13. #topic-left
  14.     width:240px
  15.     float:left
  16.     border:1px solid red
  17.     position:fixed
  18.     top:0
  19.     left:inherit; 
  20.     bottom:20px
  21.     overflow:auto
  22.  
  23. #topic-left ul{list-style:none;margin:0;padding:0;} 
  24.  
  25. #topic-left ul li{ 
  26.     width:200px
  27.     word-wrap:break-word; 
  28.     display:block
  29.     border:1px solid #09C
  30.     margin:5px 0 0 10px
  31.  
  32. #topic-left a{ 
  33.     text-decoration:none
  34.     display:block
  35.  
  36. #topic-center
  37.     max-width:960px
  38.     min-width:440px
  39.     border:1px solid #0F0
  40.     margin:0 250px
  41.  
  42. #topic-right
  43.     width:240px
  44.     float:right
  45.     border:1px solid #00F
  46.     position:fixed
  47.     top:0
  48.     right:0
  49.     bottom:20px
  50.  
  51. #footer{margin-top:-20px;} 

 

   
   
   
   
  1. > 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. <title>主题testtitle> 
  6. <link href="style/topic.css" rel="stylesheet" type="text/css" /> 
  7. <script type="text/javascript" src="style/jquery-1.4.4.min.js">script> 
  8. <script language="javascript"> 
  9. $(document).ready(function(){ 
  10.     var rightFix = ($(window).width()-$("div#topic-c").width())/2; 
  11.     $("div#topic-right").css("right",rightFix+"px"); 
  12. }); 
  13. script> 
  14. <style type="text/css"> 
  15. body{width:auto;} 
  16. style> 
  17. head> 
  18.  
  19. <body> 
  20. <div id="topic-c"> 
  21. <div id="topic-left"> 
  22.     <p>左栏:目录<br /> 
  23.         随屏幕固定<br /> 
  24.         固定宽度 
  25.     p> 
  26.     <ul> 
  27.       <li><a href="#">超长的标题里面含有deagdgrtryiskety令人崩溃了我想坑爹a>li> 
  28.       <li>aaali> 
  29.       <li>aaali> 
  30.       <li>aaali> 
  31.       <li>aaali> 
  32.       <li>aaali> 
  33.       <li>aaali> 
  34.       <li>aaali> 
  35.       <li>aaali> 
  36.       <li>aaali> 
  37.       <li>aaali> 
  38.       <li>aaali> 
  39.       <li>aaali> 
  40.       <li>aaali> 
  41.       <li>aaali> 
  42.       <li>aaali> 
  43.       <li>aaali> 
  44.       <li>aaali> 
  45.       <li>aaali> 
  46.       <li>aaali> 
  47.       <li>aaali> 
  48.       <li>aaali> 
  49.       <li>aaali> 
  50.       <li>aaali> 
  51.       <li>aaali>     
  52.       <li>aaali> 
  53.       <li>aaali> 
  54.       <li>aaali> 
  55.       <li>aaali> 
  56.       <li>aaali> 
  57.       <li>aaali>     
  58.     ul> 
  59.  
  60. div> 
  61. <div id="topic-right"> 
  62.     <p>右栏:全站导航、widget<br /> 
  63.         随屏幕固定<br /> 
  64.         固定宽度 
  65.     p> 
  66.  
  67. div> 
  68. <div id="topic-center"> 
  69.     <p>中间栏:内容<br /> 
  70.         自适应宽度    
  71.     p> 
  72.     <p>aaap> 
  73.     <p>aaap> 
  74.     <p>aaap> 
  75.     <p>aaap> 
  76.     <p>aaap> 
  77.     <p>aaap> 
  78.     <p>aaap> 
  79.     <p>aaap> 
  80.     <p>aaap> 
  81.     <p>aaap> 
  82.     <p>aaap> 
  83.     <p>aaap> 
  84.     <p>aaap> 
  85.     <p>aaap> 
  86.     <p>aaap> 
  87.     <p>aaap> 
  88.     <p>aaap> 
  89.     <p>aaap> 
  90.     <p>aaap> 
  91.     <p>aaap> 
  92.     <p>aaap> 
  93.     <p>aaap> 
  94.     <p>aaap> 
  95.     <p>aaap> 
  96.     <p>aaap> 
  97.     <p>aaap> 
  98.     <p>aaap> 
  99.     <p>aaap> 
  100. div> 
  101. <div class="clear">div> 
  102. div> 
  103. <div id="footer"> 
  104. copyright 2013 pockry@<a href="http://idlelife.org" target="_blank">idlelife.orga> All rights reserved.[powered] 
  105. div> 
  106.  
  107. body> 
  108. html> 

源码见下。