1、css實現左側寬度固定右側寬度自適應css
一、定位html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自適應</title> <style> *{ padding: 0; margin: 0; } .left{ background: red; width: 200px; height: 200px; position: absolute;/*定位*/ left: 0; top:0; } .right{ background: blue; height: 200px; margin-left: 210px; } </style> </head> <body> <div class="left"> 定寬 </div> <div class="right"> 自適應 </div> </body> </html>
二、浮動css3
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自適應</title> <style> *{ padding: 0; margin: 0; } .left{ background: red; width: 200px; height: 200px; float: left;/*浮動*/ } .right{ background: blue; height: 200px; margin-left: 210px; } </style> </head> <body> <div class="left"> 定寬 </div> <div class="right"> 自適應 </div> </body> </html>
三、marginflex
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自適應</title> <style> *{ padding: 0; margin: 0; } .left{ background: red; width: 200px; height: 200px; } .right{ background: blue; height: 200px; margin-top: -200px;/*margin*/ margin-left: 210px; } </style> </head> <body> <div class="left"> 定寬 </div> <div class="right"> 自適應 </div> </body> </html>
2、css3彈性盒模型實現自適應htm
一、上下高度固定中間高度自適應blog
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; } body,html{ height: 100%; } #contain{ display: flex; flex-direction: column;/*列 垂直方向*/ height: 100%;/*全屏效果 該元素及其父元素及html、body height:100%*/ } #top{ height: 200px; background: red; } #center { flex: 1; background: blue; } #bottom{ height: 100px; background: green; } </style> </head> <body> <div id="contain"> <div id="top">你好</div> <div id="center">你好</div> <div id="bottom">你也好</div> </div> </body> </html>
二、左側寬度固定右側寬度自適應it
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> * { margin: 0; padding: 0; } #contain { display: flex; /*父元素設置該屬性*/ } #left { width: 100px; height: 200px; background: #fff8a8; margin-right: 10px; } #right { flex: 1; /*所佔比例/份數*/ height: 200px; background: #ff9bad; } </style> </head> <body> <div id="contain"> <div id="left"></div> <div id="right"></div> </div> </body> </html>