CSS左侧固定宽 右侧自适应的实现代码(兼容所有浏览器)

2020-05-05 07:47:34易采站长站整理

HTML Markup

XML/HTML Code复制内容到剪贴板

<div id="container">  
  
<div id="left" class="aside">Left Sidebar</div>  
  
<div id="content" class="section">Main Content</div>  
  
</div>  

CSS Code

CSS Code复制内容到剪贴板

<style type="text/css">   
  
*{margin: 0;padding: 0;}   
  
#container {   
  
overflow: hidden;   
  
}   
  
    
  
#left {   
  
background: #ccc;   
  
float: left;   
  
width: 200px;   
  
margin-bottom: -99999px;   
  
padding-bottom: 99999px;   
  
    
  
}   
  
    
  
#content {   
  
background: #eee;   
  
margin-left: 200px;/*==此值等于左边栏的宽度值==*/  
  
margin-bottom: -99999px;   
  
padding-bottom: 99999px;   
  
}   
  
#left,   
  
#content {   
  
min-height: 200px;   
  
height: auto !important;   
  
height: 200px;   
  
}   
  
</style>  

方法三:

HTML Markup

XML/HTML Code复制内容到剪贴板

<div id="container">  
  
<div id="content">Main Content</div>  
  
<div id="sidebar">Left Sidebar</div>  
  
</div>  

CSS Code

CSS Code复制内容到剪贴板

*{margin: 0;padding: 0;}   
  
#container{   
  
background-color:#0ff;   
  
overflow:hidden;   
  
padding-left:220px; /* 宽度大小等与边栏宽度大小*/  
  
}   
  
* html #container{   
  
height:1%; /* So IE plays nice */  
  
}