简体   繁体   English

div背景轻松,将鼠标悬停在上面

[英]div background ease with overlay on hover

I have a div set up on my page that has an overlay appear on it when the user hovers over the div. 我在页面上设置了一个div,当用户将鼠标悬停在div上时,该页面上会显示一个叠加层。 On other websites, for example on here: http://www.elpassion.com have a really nice effect that also eases the background of the div behind. 在其他网站上,例如在以下网站上: http : //www.elpassion.com确实具有很好的效果,也减轻了后面div的背景。 I cannot seem to get this to work as effectively as i have seen and was looking for some support and guidance. 我似乎无法使它像我所看到的那样有效地工作,并且正在寻找一些支持和指导。

https://jsfiddle.net/Lopcnsuq/ https://jsfiddle.net/Lopcnsuq/

HTML 的HTML

<div class="portfolio-project">
<div class="portfolio-project-image">
<ul class="portfolio-project-image">
    <li>
        <div class="portfolio-project-image-one"></div>
        <a href="images/flyer_mock_up.jpg" class="html5lightbox" data-width="853" data-height="480" title="">
    <div class="portfolio-overlay">
        <div class="bt4">Marks & Spencer</div>
        <div class="bt5">Summer Fete A5 Flyers</div>
    </div>
</a>
    </li>
</ul>
</div>
</div>

CSS 的CSS

.portfolio-project {
    width: 32%;
    height: 373px;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
    margin-left:15px;
    float:left;
}


.portfolio-project-image{
    width: 100%;
    height: 373px;
}

.portfolio-project-image-one{
    width: 100%;
    height: 373px;
    background-image:url(../images/flyer_mock_up.jpg);
    background-position:center;

}



.portfolio-project-image-one:hover{
    width: 100%;
    height: 373px;
    background-image:url(../images/flyer_mock_up.jpg);
    background-position:center;
    display:block;

}

.portfolio-overlay {
  width:100%;
  height:100%;
  opacity: 0.75;
  position:absolute;
  background-color:black;
  transition: top 0.3s ease-in-out;
  display:block;
  -webkit-transition: top 0.3s ease-in-out;
            transition: top 0.3s ease-in-out;

}
.portfolio-overlay div {
    position:relative;
  display:inline-block;;

}

ul.portfolio-project-image { 
    list-style: none; 
    width:100% 

}

ul.portfolio-project-image li {
    position: relative;
    display: inline-block;
    width:100%;
  height: 100%;
  overflow: hidden;
  transition: 2s;
    -moz-transition: 2s;
    -webkit-transition: 2s;
    }


li:hover .portfolio-overlay {
  top: 0;
  display:block;
   transition: 2s;
    -moz-transition: 2s;
    -webkit-transition: 2s;}


.bt4 {
    text-align: center;
    margin-top: 160px;
    font: 200 12px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
}
.bt5 {
    text-align: center;
    font: 100 14px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 16px;
    font-weight: 200;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 10px;
}

.bt5 a {
    text-align: center;
    font: 100 14px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 16px;
    font-weight: 200;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 10px;
    text-decoration:none;
}

.bt6 {
    text-align: center;
    font: 200 12px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 30px;
    font-weight: 200;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 30px;
}

I changed your fiddle a little bit so that your background-image zooms slightly when you hover the image as shown in the elpassion-example. 我稍微改变了小提琴,以便当您将图像悬停在elpassion示例中时,背景图像会稍微缩放。

You can zoom/stretch the background-image of a div on hover with the following css: 您可以使用以下CSS在缩放时缩放/拉伸div的背景图像:

.portfolio-project-image:hover {
    background-size: 102% 102%;
    background-repeat: no-repeat;
    background-position: center center;
}

You can find your updated fiddle with an example-background-image at the following link: https://jsfiddle.net/Lopcnsuq/9/ 您可以在以下链接中找到带有示例背景图像的更新过的小提琴: https : //jsfiddle.net/Lopcnsuq/9/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM