0

为什么我的鼠标悬停没有穿过整个侧边栏?我需要侧边栏悬停才能穿过整个侧边栏,而不仅仅是一点点。我将如何解决这个问题?

#main-container {
  display: table;
  width: 100%;
  height: 100%;
}

#sidebar {
  font-family: sans-serif;
  display: table-cell;
  width: 3.7%;
  vertical-align: top;
  background-color: #0E4D92;
}

#sidebar a {
  display: block;
  padding: 10px;
  color: rgba(255, 255, 255);
  margin: 15px 30px 0 0;
  text-decoration: none;
  position: relative;
  left: 30px;
}

#sidebar a:hover {
  background-color: #73C2FB;
}

#content {
  display: table-cell;
  width: 85%;
  vertical-align: top;
  padding: 10px 0 0 10px;
}
<div id="main-container">
  <div id="sidebar">
    <img src="img/LetterLogo.png" />
    <a href="index.html">Home</a>
    <a href="about.html">Order</a>
    <a href="#">Portfolio</a>
    <a href="#">History</a>
    <a href="#"></a>
  </div>
</div>

4

1 回答 1

0

问题是由您创建索引的方式引起的#sidebar a- 使用left: 30pxwith position: relative。删除两者,然后使用padding: 10px 10px 10px 40px;。这样,背景将从左边缘开始,文本仍然会向内缩进。

#main-container {
  display: table;
  width: 100%;
  height: 100%;
}

#sidebar {
  font-family: sans-serif;
  display: table-cell;
  width: 3.7%;
  vertical-align: top;
  background-color: #0E4D92;
}

#sidebar a {
  display: block;
  padding: 10px 10px 10px 40px;
  color: rgba(255, 255, 255);
  margin: 15px 30px 0 0;
  text-decoration: none;
}

#sidebar a:hover {
  background-color: #73C2FB;
}

#content {
  display: table-cell;
  width: 85%;
  vertical-align: top;
  padding: 10px 0 0 10px;
}
<div id="main-container">
  <div id="sidebar">
    <img src="img/LetterLogo.png" />
    <a href="index.html">Home</a>
    <a href="about.html">Order</a>
    <a href="#">Portfolio</a>
    <a href="#">History</a>
    <a href="#"></a>
  </div>
</div>

于 2019-11-30T19:31:49.513 回答