Html ,CSS 固定宽度高亮悬停背景

标签 html css

我正在尝试在列表项上实现全宽悬停背景。

enter image description here

我还需要让灰色背景全宽向左。

如何实现:

HTML:

<div class="col-md-5 col-xs-12 additonal-resources-cont">
                <h3 class="header-additnl-resources">Additional Resources </h3>
                <ul class="additional-resrc-ul nopadding">
                    <li><a href="" class="additional-resources-href">Login / Register</a></li>
                    <li><a href="" class="additional-resources-href">Request Samples</a></li>
                    <li><a href="" class="additional-resources-href">Technical Documentation</a></li>
                </ul>
            </div>

CSS:

.additional-resources-href:hover {
    background: #1daeeb;
    opacity: 4.5;
    background-color: #BFCDD5 !important;
}


.additional-resources-href {
    color: black;
    text-decoration: none;
}

.additional-resrc-ul li:before {
    content: "• ";
    font-weight: bold;
    color: #1DAEEB;
}

.additional-resrc-ul li:hover {
    background: #1daeeb;
    opacity: 4.5;
    background-color: #BFCDD5;
}

.additional-resrc-ul {
    margin: 0px;
    padding: 0px;
    margin-left: 10%;
    font-weight: 300;
    font-size: 10px;
    line-height: 3.5em;
}

最佳答案

您可以使用伪元素,它会溢出到 li 之外并覆盖所有宽度,如下所示:

.additional-resources-href:hover {
  background: #1daeeb;
  opacity: 4.5;
  background-color: #BFCDD5 !important;
}

.additional-resources-href {
  color: black;
  text-decoration: none;
}

.additional-resrc-ul li {
  position:relative;
}
.additional-resrc-ul li:before {
  content: "• ";
  font-weight: bold;
  color: #1DAEEB;
}

.additional-resrc-ul li:after {
  content: "";
  z-index: -1;
  position: absolute;
  top: 0;
  bottom: 0;
  left: -30%;
  right: 0;
}

.additional-resrc-ul li:hover {
  
  opacity: 4.5;
}

.additional-resrc-ul li:hover::after {
  background: #BFCDD5;
}

.additional-resrc-ul {
  margin: 0px;
  padding: 0px;
  margin-left: 10%;
  font-weight: 300;
  font-size: 10px;
  line-height: 3.5em;
}
<div class="col-md-5 col-xs-12 additonal-resources-cont">
  <h3 class="header-additnl-resources">Additional Resources </h3>
  <ul class="additional-resrc-ul nopadding">
    <li><a href="" class="additional-resources-href">Login / Register</a></li>
    <li><a href="" class="additional-resources-href">Request Samples</a></li>
    <li><a href="" class="additional-resources-href">Technical Documentation</a></li>
  </ul>
</div>

关于Html ,CSS 固定宽度高亮悬停背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47606247/

相关文章:

Internet Explorer 7 和 8 上的 xhtml 代码的 css 问题

javascript - 如何在禁用 JavaScript 时显示不同的内容?

javascript - 当我在 chrome mobile 中向下滚动时,绝对定位的 DIV 会改变位置,如何解决这个问题?

html - 为什么在 float 元素之后忽略 html 元素的上边距?

javascript - Iframe 元素通过 Id 访问,给出 null

javascript - JQuery/JavaScript - 从另一个按钮点击事件触发按钮点击

html - 如何在 <ul> 中设置元素符号背景的样式?

css - 无法使 translate3d Z 属性起作用

jquery - 阻止 addClass 多次触发

html - 将图像和文本放在跨度中的同一行上