html - 为什么我的悬停命令没有穿过整个栏?浅蓝色应该穿过整个条形,而不是那么多

标签 html css hover navbar

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

#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>

最佳答案

问题是由您创建 #sidebar a 索引的方式引起的 - 使用 left: 30pxposition: 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>

关于html - 为什么我的悬停命令没有穿过整个栏?浅蓝色应该穿过整个条形,而不是那么多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59119501/

相关文章:

html - 透明工具栏上的透明文本

html - 将鼠标悬停在 div 上时尝试显示图像

javascript - 如何使用 ImageButtons 在 GridView TemplateField 中保留图像超链接的样式/悬停功能

Jquery 旋转,在 mouseenter 上运行,在 mouseout 上停止

html - <p> 悬停时显示在 img 上

html - 使用css将文本对齐到html代码中的网页顶部

html - 无法在第一个和最后一个 child 上进行异常形状的悬停

javascript - knockout 输入绑定(bind)不起作用

jquery - 以编程方式在可排序之间移动 li 标签

javascript - 文本编辑器错误