我有这个Example

HTML:

<ul class="img-list">
    <li>
        <img src="http://s11.postimg.org/ynw9rnexf/Cetina_river.jpg" width="360px" height="280px" />
<span class="text-content"><span>
 Text To Display</span></span>
    </li>
</ul>


CSS:

ul.img-list {
     list-style-type: none;
     margin: 0;
     padding: 0;
     text-align: center;
 }
 ul.img-list {
     display: inline-block;
     height: 150px;
     margin: 0 5px 1em 0;
     position: relative;
     width: 360px;
     margin-top:-5px;
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     color: white;
     cursor: pointer;
     display: table;
     height: 150px;
     left: 0;
     position: absolute;
     top: 0;
     width: 150px;
 }
 span.text-content span {
     display: table-cell;
     text-align: center;
     vertical-align: middle;
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     color: white;
     cursor: pointer;
     display: table;
     height: 150px;
     left: 0;
     position: absolute;
     top: 0;
     width: 150px;
     opacity: 0;
 }
 ul.img-list li:hover span.text-content {
     opacity: 1;
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     color: white;
     cursor: pointer;
     display: table;
     height: 280px;
     left: 0;
     position: absolute;
     top: 0;
     width: 360px;
     opacity: 0;
     -webkit-transition: opacity 500ms;
     -moz-transition: opacity 500ms;
     -o-transition: opacity 500ms;
     transition: opacity 500ms;
     font-family: Droid Arabic Kufi;
     font-size: xx-large;
 }


在鼠标悬停时,我必须在图像上方显示文本。

我需要的是使此文本在图像本身的底部恒定,然后将鼠标悬停在顶部。

我的意思是,在图像的最后一个50px中,我希望黑色背景具有恒定的文本,并且当鼠标悬停在相同功能上时将运行。

谢谢大家的建议。

最佳答案

这是您想要达到的目标吗? Fiddle



* {
  margin: 0;
  padding: 0;
  border-spacing: 0;
  top: 0;
}
ul.img-list {
  list-style-type: none;
  text-align: center;
}
ul.img-list {
  border-spacing: 0;
  display: inline-block;
  height: 150px;
  position: relative;
  width: 360px;
}
span.text-content span {
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}
ul.img-list li:hover span.text-content {
  opacity: 1;
  background: rgba(0, 0, 0, 0.5);
  margin-top: -280px;
  height: 280px;
  -webkit-transition: 500ms;
  -moz-transition: 500ms;
  -o-transition: 500ms;
  transition: 500ms;
}
span.text-content {
  background: black;
  position: relative;
  color: white;
  cursor: pointer;
  display: table;
  height: 50px;
  left: 0;
  top: -5px;
  width: 360px;
  opacity: 1;
  -webkit-transition: 500ms;
  -moz-transition: 500ms;
  -o-transition: 500ms;
  transition: 500ms;
  font-family: Droid Arabic Kufi;
  font-size: xx-large;
  z-index: 2;
}

<ul class="img-list">
  <li>
    <img src="http://s11.postimg.org/ynw9rnexf/Cetina_river.jpg" width="360px" height="280px" /> <span class="text-content">
            <span>Text To Display</span>
    </span>
  </li>
</ul>

关于html - 鼠标悬停在图像上之前的常量文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29184679/

10-12 15:17