运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { margin: 0; font-family: "Lato", sans-serif; } .sidebar { margin: 0; padding: 0; width: 200px; background-color: #f1f1f1; position: fixed; height: 100%; overflow: auto; } .sidebar a { display: block; color: black; padding: 16px; text-decoration: none; } .sidebar a.active { background-color: #04AA6D; color: white; } .sidebar a:hover:not(.active) { background-color: #555; color: white; } div.content { margin-left: 200px; padding: 1px 16px; height: 1000px; } @media screen and (max-width: 700px) { .sidebar { width: 100%; height: auto; position: relative; } .sidebar a {float: left;} div.content {margin-left: 0;} } @media screen and (max-width: 400px) { .sidebar a { text-align: center; float: none; } } </style> </head> <body> <div class="sidebar"> <a class="active" href="#home">Home</a> <a href="#news">News</a> <a href="#contact">Contact</a> <a href="#about">About</a> </div> <div class="content"> <h2>Responsive Sidebar Example</h2> <p>This example use media queries to transform the sidebar to a top navigation bar when the screen size is 700px or less.</p> <p>We have also added a media query for screens that are 400px or less, which will vertically stack and center the navigation links.</p> <h3>Resize the browser window to see the effect.</h3> </div> </body> </html>