html - css 顶部和底部不适用于元素

标签 html css hover

当图像悬停时,我试图将图像文本叠加层放置在图像上方。 topbottom 没有用。

这是代码-

.projects {
  padding-top: 50px;
}

.desktop-image {
  position: relative;
}

.desktop-image:hover img {
  -webkit-filter: blur(5px);
  filter: blur(5px);
  cursor: e-resize;
}

.desktop-image > img {
  width: 700px;
}

.img_description {
  position: absolute;
  top: -13%;
  bottom: 0;
  left: 0;
  right: 0;
  color: #000;
  visibility: hidden;
  opacity: 0;
  transition: opacity .7s, visibility .7s;
  font-family: inherit;
}

.desktop-image > a:hover .img_description {
  visibility: visible;
  opacity: 1;
}
 <div class="projects">
  <div class="desktop-image">
    <a class="desktop-image" href="https://www.stellamccartney.com/gb" target="_blank">
      <img src="https://www.thesun.co.uk/wp-content/uploads/2017/08/nintchdbpict000342472436.jpg?strip=all&w=960&quality=100">
      <p class="img_description">
        An event directory that I<br> founded. Development, design &<br> content by me.
      </p>
    </a>
  </div>
</div>

最佳答案

使用 .img-description 上的位置和宽度设置,如下所示。并且由于您使用不透明度 0 和 1,您可以清除可见性设置(反之亦然)文本居中当然是可选的,白色文本颜色也是如此(虽然确实提高了可见性) .

.projects {
  padding-top: 50px;
}

.desktop-image {
  position: relative;
}

.desktop-image:hover img {
  -webkit-filter: blur(5px);
  filter: blur(5px);
  cursor: e-resize;
}

.desktop-image > img {
  width: 700px;
}

.img_description {
  position: absolute;
  bottom: 13%;
  left: 0;
  right: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  opacity: 0;
  transition: opacity .7s, visibility .7s;
  font-family: inherit;
}

.desktop-image > a:hover .img_description {
  opacity: 1;
}
<div class="projects">
  <div class="desktop-image">
    <a class="desktop-image" href="https://www.stellamccartney.com/gb" target="_blank">
      <img src="https://www.thesun.co.uk/wp-content/uploads/2017/08/nintchdbpict000342472436.jpg?strip=all&w=960&quality=100">
      <p class="img_description">
        An event directory that I<br> founded. Development, design &<br> content by me.
      </p>
    </a>
  </div>
</div>

关于html - css 顶部和底部不适用于元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46202964/

相关文章:

javascript - 有没有办法在IE中的输入框中获取所选文本的偏移量?

javascript - getElementByID div 标签内的 PHP echo 语句

css - 所有 css 字体属性的一个 css 声明

css hover 和 immidiatily 先例不起作用

html - 如何同时在框上悬停和过渡?只使用 css 和 html

javascript - CSS 在 Angular Ionic App 上第二次重新排列

javascript - 如何在提交表单之前立即对 radio 输入设置 CustomValidity

CSS - 选择元素之间的特定元素

CSS 动画涉及 Safari 上的不透明度、缩放和翻译问题

html - 使用 css 在图像映射上悬停时更改图像