跳跃的背景

时间:2017-10-20 11:46:12

标签: html css

如何防止我的背景跳转?我希望在我的背景末尾有一条红线,但是当我在文章上盘旋时,它会四处跳跃。



div {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    margin-left: 20px;
    font-weight: 500;
    color: white;
    font-size: 20px;
    line-height: 21px;
}

.big-column {
    height: 396px;
    width: 311px;
    background-size: cover;
    box-sizing: border-box;
    background-image: url("https://image.freepik.com/free-vector/modern-technological-elements-with-transparent-background_1035-7108.jpg");
}

.big-column:hover {
    border-bottom: 5px solid #e60000;
    text-decoration: underline;
    color: white;
}

<article class="big-column big-column-1">
    <div class="column-description">
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
    </div>
</article>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:1)

.big-column上加上边框,并将其颜色设置为transparent。在:hover上,您可以将颜色更改为您想要的颜色。

div {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  margin-left: 20px;
  font-weight: 500;
  color: white;
  font-size: 20px;
  line-height: 21px;
}

.big-column {
  height: 396px;
  width: 311px;
  background-size: cover;
  box-sizing: border-box;
  background-image: url("https://image.freepik.com/free-vector/modern-technological-elements-with-transparent-background_1035-7108.jpg");
  border-bottom: 5px solid transparent;
}

.big-column:hover {
  border-color: #e60000;
  text-decoration: underline;
  color: white;
}
<article class="big-column big-column-1">
  <div class="column-description">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
  </div>
</article>

答案 1 :(得分:0)

border-bottom更改为box-shadow

&#13;
&#13;
div{
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  margin-left: 20px;
  font-weight: 500;
  color: white;
  font-size: 20px;
  line-height: 21px;
}

.big-column {
  height: 396px;
  width: 311px;
  background-size: cover;
  box-sizing: border-box;
  background-image: url("https://image.freepik.com/free-vector/modern-technological-elements-with-transparent-background_1035-7108.jpg");
}

.big-column:hover {
  box-shadow: inset 0 -5px 0 #e60000;
  text-decoration: underline;
  color: white;
}
&#13;
<article class="big-column big-column-1">
  <div class="column-description">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
  </div>
</article>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

您需要做的就是将box-sizing课程的.big-column更改为content-box

答案 3 :(得分:-1)

我添加了位置:固定;在你的背景课上,看看吧。我认为这应该有效!

&#13;
&#13;
 
  div{
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    margin-left: 20px;
  font-weight: 500;
    color: white;
    font-size: 20px;
    line-height: 21px;
  }

.big-column {
  height: 396px;
  width: 311px;
  position: fixed;
  background-size: cover;
  box-sizing: border-box;
  background-image: url("https://image.freepik.com/free-vector/modern-technological-elements-with-transparent-background_1035-7108.jpg");
}
.big-column:hover {
  border-bottom: 5px solid #e60000;
  text-decoration: underline;
  color: white;
}
&#13;
<article class="big-column big-column-1">
                  <div class="column-description">

                    <p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
                    
                  </div>


            </article>
&#13;
&#13;
&#13;