CSS 网格混乱我的页面似乎忽略了 css

问题描述 投票:0回答:1

由于各种原因,我最近决定恢复我的 CSS 网格设计。遗憾的是,这并没有成功,因为页面似乎忽略了我编写的 CSS。 CSS代码如下:

    html {
  margin-left: 0;
   margin-top: 0;
}

table,
th,
td {
  border: 1px solid;
}

body {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 60px 1fr auto;
  grid-template-columns: 300px auto;
  grid-template-areas: 'menubtn header '
    'sidebar content'
    'footer footer';
}

#menubtn {
  grid-area: menubtn;
 }

#header {
   grid-area: header;
  background-color: white;
}

#sidebar {
  grid-area: sidebar;
  background-color: white;
}

#content {
  grid-area: content;
}

#footer {
  grid-area: footer;
  background-color: white;
}

#hidden {
  display: none;
  visibility: hidden;
}

h1 {
  color: #330099;
} 

h2 {
  color: #330099;
}

h3 {
  color: #330099;
}

a:link,
a:visited {
  color: #FFF;
  font-weight: bold;
  background-color: #09F;
  border: 1px solid #0066cc;
  padding: 3px;
  text-decoration: none
}

#content a:link {
  color: #FFF;
  font-weight: bold;
  background-color: #09F;
  border: 1px solid #0066cc;
  padding: 1px;
  text-decoration: none
}

#content a:visited {
  color: #FFF;
  font-weight: bold;
  background-color: #09F;
  border: 1px solid #0066cc;
  padding: 1px;
  text-decoration: none
}

a:hover {
  background-color: #06C
}

我构建了一个小页面来说明问题。在这里:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="wvv_grid.css" type="text/css">
   <title>
      Test page for toggling menu
   </title>
   <script>
  // toggle-menu.js
  document.getElementById("toggle-btn").addEventListener("click", function () {
     var sidebar = document.getElementById("#sidebar");
     sidebar.classList.toggle("#hidden");
  });

   </script>
</head>
<div id="body">
   <div id="menubtn">
      <button id="toggle-btn">Toggle Menu</button>
   </div>
   <div id="header">
      <h1>Welcome to my test page</h1>
   </div>
   <div id="sidebar">
      <ul>
         <li>this</li>
         <li>item</li>
         <li>tests</li>
         <li>the</li>
         <li>button</li>
      </ul>
   </div>
   <div id="content">
      <h2>welcome again!</h2>
      <p>this page has been created to test my button to toggle menus</p>
   </div>
</div>

实际页面是使用 PHP 编写的,但这是一个简化版本。 目前,它似乎按顺序显示,但内容应显示在菜单旁边。 我确信有一个简单的解决方案可以解决这个问题,这可能是由于我对网格应该如何工作的误解。 非常感谢您的帮助。

html css
1个回答
0
投票

在您的样式中,您编写了

body {}
而不是
#body {}
,因为这些样式是针对 ID 为
div
body
编写的。

© www.soinside.com 2019 - 2024. All rights reserved.