html - 不移动背景的过渡(CSS 和 HTML)

标签 html css hover transition

我在编码方面还是个新手,所以你会在 css 中看到一些不必要的代码。 我的问题是,我想让背景在悬停时保持/静态,我相信我的悬停风格被称为“幻灯片”。但是当我悬停时,背景也悬停了。因此,我需要有关如何在悬停时使背景静态的帮助。

p/s: 请保留 avpb 的余量 :)

CSS:

#avpb {
background: rgba(0, 0, 0, 0.6);
width: 160px; 
height: 220px;
border: 1px solid #000000;
padding: 19.5px;
margin-top: -10px;
margin-left: 555px;
position: absolute;
}

#avp {
position: absolute;
width: 160px;
height: 220px;
}

#avp img {
position: absolute;
z-index: 0;
}

.overlay {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
-webkit-transition:all .3s ease-out;
-moz-transition:all .3s ease-out;
-ms-transition:all .3s ease-out;
-o-transition:all .3s ease-out;
transition:all .3s ease-out;
}

#avp:hover > .overlay {
opacity: 1;
width: 160px;
height: 220px 
height:auto;
background: rgba(0, 0, 0, 0.6);
-webkit-transform:translate(0px,10px);
-moz-transform:translate(0px,10px);
-ms-transform:translate(0px,10px);
-o-transform:translate(0px,10px);
transform:translate(0px,10px);
}

.button {
width: 160px;
height: 220px;
position: absolute;
}

.button a {
font-family: Lato;
font-size: 10px;
letter-spacing: 1px;
width: 80px;
height: 25px;
line-height: 25px;
margin-left: auto;
margin-right: auto;
background: rgba(0, 0, 0, 0.6);
border: 1px solid #000000;
text-align: center;
text-decoration: none;
padding: 5px;
color: #ffffff !important;
display: block;
transition: 0.5s ease; 
-webkit-transition: 0.5s ease; 
-o-transition: 0.5s ease; 
-ms-transition: 0.5s ease; 
}

.button a:hover {
background: rgba(0, 0, 0, 0.6);
border: 1px solid #4cd1db;
color: #4cd1db !important;
text-decoration: none;
letter-spacing: 2px;
transition: 0.5s ease; 
-webkit-transition: 0.5s ease; 
-o-transition: 0.5s ease; 
-ms-transition: 0.5s ease; 
}

HTML:

<div id="avpb">
<div id="avp">
<img src="http://www.imvu.com/catalog/web_av_pic.php?u=87116145">
<div class="overlay">
<div class="button">
<br>
<br>
<a href="http://www.imvu.com/catalog/web_add_contact.phpcontact=applesunsweets">add</a>
<br>
<a href="javascript:IMVU.messagePopupShow({force_recipient_id:87116145})">message</a>
</div>
</div>
</div>
</div>

这是一个 JSFiddle

最佳答案

然后你应该让 .button 变形。我在你的 css 文件中添加了一些样式,很难解释,只是尝试将它与你的原始代码进行比较:)。

#avpb {
  background: rgba(0, 0, 0, 0.6);
  width: 160px;
  height: 220px;
  border: 1px solid #000000;
  padding: 19.5px;
  margin-top: -10px;
  margin-left: 555px;
  position: absolute;
}

#avp {
  position: absolute;
  width: 160px;
  height: 220px;
}

#avp img {
  position: absolute;
  z-index: 0;
}

.overlay {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0;
  -webkit-transition: all .3s ease-out;
  -moz-transition: all .3s ease-out;
  -ms-transition: all .3s ease-out;
  -o-transition: all .3s ease-out;
  transition: all .3s ease-out;
}
.button{
  -webkit-transition: all .3s ease-out;
  -moz-transition: all .3s ease-out;
  -ms-transition: all .3s ease-out;
  -o-transition: all .3s ease-out;
  transition: all .3s ease-out;
}

#avp:hover>.overlay {
  opacity: 1;
  width: 160px;
  height: 220px height:auto;
  background: rgba(0, 0, 0, 0.6);
}
#avp:hover>.overlay>.button {
  opacity: 1;
  width: 160px;
  height: 220px height:auto;
  -webkit-transform: translate(0px, 10px);
  -moz-transform: translate(0px, 10px);
  -ms-transform: translate(0px, 10px);
  -o-transform: translate(0px, 10px);
  transform: translate(0px, 10px);
}

.button {
  width: 160px;
  height: 220px;
  position: absolute;
}

.button a {
  font-family: Lato;
  font-size: 10px;
  letter-spacing: 1px;
  width: 80px;
  height: 25px;
  line-height: 25px;
  margin-left: auto;
  margin-right: auto;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #000000;
  text-align: center;
  text-decoration: none;
  padding: 5px;
  color: #ffffff !important;
  display: block;
  transition: 0.5s ease;
  -webkit-transition: 0.5s ease;
  -o-transition: 0.5s ease;
  -ms-transition: 0.5s ease;
}

.button a:hover {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #4cd1db;
  color: #4cd1db !important;
  text-decoration: none;
  letter-spacing: 2px;
  transition: 0.5s ease;
  -webkit-transition: 0.5s ease;
  -o-transition: 0.5s ease;
  -ms-transition: 0.5s ease;
}
<div id="avpb">
  <div id="avp">
    <img src="http://www.imvu.com/catalog/web_av_pic.php?u=87116145">
    <div class="overlay">
      <div class="button">
        <br>
        <br>
        <a href="http://www.imvu.com/catalog/web_add_contact.phpcontact=applesunsweets">add</a>
        <br>
        <a href="javascript:IMVU.messagePopupShow({force_recipient_id:87116145})">message</a>
      </div>
    </div>
  </div>
</div>

关于html - 不移动背景的过渡(CSS 和 HTML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42932334/

相关文章:

html - css hover 不适用于先例元素

javascript - 将鼠标悬停在列表项上以更改不同 div 的属性

HTML 表格列宽未按预期显示

javascript - 按 f5 或刷新按钮更新 URL

javascript - 根据div的大小改变字体大小

jquery - 旋转文本jquery

html - IE 7 & 8 下拉问题

html - :hover 上的幻灯片闪烁图像

javascript - 在移动屏幕上调整 dojox 图表的大小

css - 将鼠标悬停在 DIV 上也会影响 DIV 内的链接