如果在PC訪問,就會顯示在一行,如果在手機訪問,就會顯示為三行。(視手機屏幕的分辨率定)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=0.5,maximum-scale=1,minimum-scale=1,user-scalable=no"> <title>最簡單的css實現頁面寬度自適應</title> <style> div.rxs { width: 100%; height: auto; } div.rxleft { width: auto; float: left; height: auto; margin-bottom: 0; margin-top: 10px; padding-right: 10px; } hr { margin-top: 10px; margin-bottom: 0; border-top: 1px solid #CCC; } </style> </head> <body> <div class="rxs"> <div class="rxleft"> 第一段內容,可以是任何html標簽 </div> <div class="rxleft"> 第二段內容,可以是任何html標簽 </div> <div class="rxleft"> 第三段內容,可以是任何html標簽 </div> <div style="clear:both"></div> </div> <hr> </body> </html>
