W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <title>Page Title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { box-sizing: border-box; } /* 设置 body 的样式 */ body { font-family: Arial; margin: 0; } /* 页眉/LOGO */ .header { padding: 60px; text-align: center; background: #1abc9c; color: white; } /* 设置顶部导航栏的样式 */ .navbar { display: flex; background-color: #333; } /* 设置导航栏链接的样式 */ .navbar a { color: white; padding: 14px 20px; text-decoration: none; text-align: center; } /* 悬停时改变颜色 */ .navbar a:hover { background-color: #ddd; color: black; } /* 列容器 */ .row { display: flex; flex-wrap: wrap; } /* 创建两个彼此相邻的不相等的列 */ /* 侧栏/左侧列 */ .side { flex: 30%; background-color: #f1f1f1; padding: 20px; } /* 主列 */ .main { flex: 70%; background-color: white; padding: 20px; } /* 伪图像,仅用于此例 */ .fakeimg { background-color: #aaa; width: 100%; padding: 20px; } /* 页脚 */ .footer { padding: 20px; text-align: center; background: #ddd; } /* 响应式布局 - 当屏幕宽度小于 700 像素时,使两列相互堆叠,而不是彼此相邻 */ @media screen and (max-width: 700px) { .row, .navbar { flex-direction: column; } } </style> </head> <body> <!-- Note --> <div style="background:yellow;padding:5px"> <h4 style="text-align:center">请调整浏览器窗口的大小以查看响应效果。</h4> </div> <!-- Header --> <div class="header"> <h1>My Website</h1> <p>With a <b>flexible</b> layout.</p> </div> <!-- Navigation Bar --> <div class="navbar"> <a href="#">Link</a> <a href="#">Link</a> <a href="#">Link</a> <a href="#">Link</a> </div> <!-- The flexible grid (content) --> <div class="row"> <div class="side"> <h2>About Me</h2> <h5>Photo of me:</h5> <div class="fakeimg" style="height:200px;">Image</div> <p>Some text about me in culpa qui officia deserunt mollit anim..</p> <h3>More Text</h3> <p>Lorem ipsum dolor sit ame.</p> <div class="fakeimg" style="height:60px;">Image</div><br> <div class="fakeimg" style="height:60px;">Image</div><br> <div class="fakeimg" style="height:60px;">Image</div> </div> <div class="main"> <h2>TITLE HEADING</h2> <h5>Title description, Dec 7, 2017</h5> <div class="fakeimg" style="height:200px;">Image</div> <p>Some text..</p> <p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p> <br> <h2>TITLE HEADING</h2> <h5>Title description, Sep 2, 2017</h5> <div class="fakeimg" style="height:200px;">Image</div> <p>Some text..</p> <p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p> </div> </div> <!-- Footer --> <div class="footer"> <h2>Footer</h2> </div> </body> </html>