运行结果尺寸: 300 x 150
x
 
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.cn/w3css/4/w3.css">
<body>
<!-- Sidebar -->
<div class="w3-sidebar w3-bar-block" style="display:none" id="mySidebar">
  <button onclick="w3_close()" class="w3-bar-item w3-button w3-large">Close &times;</button>
  <a href="#" class="w3-bar-item w3-button">链接 1</a>
  <a href="#" class="w3-bar-item w3-button">链接 2</a>
  <a href="#" class="w3-bar-item w3-button">链接 3</a>
</div>
<!-- Page Content -->
<div class="w3-teal">
  <button class="w3-button w3-teal w3-xlarge" onclick="w3_open()"></button>
  <div class="w3-container">
    <h1>我的页面</h1>
  </div>
</div>
<img src="img_car.jpg" alt="汽车" style="width:100%">
<div class="w3-container">
<p>在此示例中,侧边栏是隐藏的 (style="display:none")</p>
<p>当您点击左上角的菜单图标时显示。</p>
<p>打开时,它会隐藏所有页面内容 (style.width="100%")。</p>
</div>
<script>
function w3_open() {
  document.getElementById("mySidebar").style.width = "100%";
  document.getElementById("mySidebar").style.display = "block";
}
function w3_close() {
  document.getElementById("mySidebar").style.display = "none";
}
</script>
     
</body>
</html> 
×

报个问题: