首页
CSS
CSS 模板
Tryit:模板 2 - 使用浮动
运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html lang="en"> <head> <title>CSS Template</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { box-sizing: border-box; } body { font-family: Arial, Helvetica, sans-serif; } /* Style the header */ .header { background-color: #f1f1f1; padding: 30px; text-align: center; font-size: 35px; } /* Create three unequal columns that floats next to each other */ .column { float: left; padding: 10px; height: 300px; /* Should be removed. Only for demonstration */ } /* Left and right column */ .column.side { width: 25%; } /* Middle column */ .column.middle { width: 50%; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; } /* Style the footer */ .footer { background-color: #f1f1f1; padding: 10px; text-align: center; } /* Responsive layout - makes the three columns stack on top of each other instead of next to each other */ @media (max-width: 600px) { .column.side, .column.middle { width: 100%; } } </style> </head> <body> <h2>CSS Template using Float</h2> <p>In this example, we have created a header, three unequal columns and a footer. On smaller screens, the columns will stack on top of each other.</p> <p>Resize the browser window to see the responsive effect.</p> <div class="header"> <h2>Header</h2> </div> <div class="row"> <div class="column side" style="background-color:#aaa;">Column</div> <div class="column middle" style="background-color:#bbb;">Column</div> <div class="column side" style="background-color:#ccc;">Column</div> </div> <div class="footer"> <p>Footer</p> </div> </body> </html>