Html,CSS固定宽度突出显示悬停背景

时间:2017-12-02 09:07:55

标签: html css css3

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

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;
}

2 个答案:

答案 0 :(得分:0)

你可以使用在li之外溢出的伪元素并覆盖所有宽度,如下所示:

&#13;
&#13;
.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;
}
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

在这里,我使用flex列创建菜单,并将鼠标悬停应用于每个项目并添加过渡。

&#13;
&#13;
.container{
  display: flex;
  justify-content: space-between;
 }

.resources-list{
  display: flex;
  flex-direction: column;
  flex: 0 0 20%;
}

.resources-item{
  transition: all 250ms linear;
}

.resources-item:hover{
  background-color: gray;
}

.resources-item:before{
  content: '• ';
}

.app-content{
  flex: 0 0 75%;
}
&#13;
<div class="container">
        <div class="resources-list">
            <h3>Resources List</h3>
            <div class="resources-item">lorem3</div>
            <div class="resources-item">lorem3</div>
            <div class="resources-item">lorem3</div>
        </div>
        <div class="app-content">
              Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorum mollitia illum voluptates. Cumque earum cupiditate explicabo dolorum, praesentium dolor quia consequatur incidunt iste excepturi blanditiis dolores quibusdam odio quas quo.
        </div
    </div>
&#13;
&#13;
&#13;