简体   繁体   English

在悬停上移动文本

[英]On Hover Move The Text Up

So I'm trying to move up the text when you hover over the image but I can't seem to get it to work. 所以当你将鼠标悬停在图像上时,我正试图向上移动文本,但我似乎无法让它工作。 I tried using :hover and then using padding-bottom to move it up but it didn't work. 我尝试使用:悬停然后使用padding-bottom移动它但它不起作用。 So I basically want the text "Nature" or "Bengal Tiger" to move up when you hover over the image. 因此,当您将鼠标悬停在图像上时,我基本上希望文本“自然”或“孟加拉虎”向上移动。 Here's a pic that illustrates what I want to achieve. 这是一张图片,展示了我想要实现的目标。

Here's the code 这是代码

http://jsfiddle.net/Qf4Ka/10/ http://jsfiddle.net/Qf4Ka/10/

HTML HTML

<section id="top-container" class="top-column" style="width:1050px; height:400px; ">

<div class="image" style="float:left;"><img src="http://www.hdwallpapersinn.com/wp-content/uploads/2012/09/HD-Wallpaper-1920x1080.jpg" border="0"; width="263"; height="200" style="display: block; border-top: 1px solid #dddddd; border-bottom: 1px solid #dddddd; border-right: 1px solid #dddddd;">
<h4 style="font-size:30px; top: 90px; ">Nature</h4>
</div>

<div class="image" style="float:left;"><img src="http://www.hdwallpapersart.com/wp-content/uploads/2013/04/tiger_wallpapers_hd_Bengal_Tiger_hd_wallpaper1.jpg" border="0"; width="262"; height="200" style="display: block; border-top: 1px solid #dddddd; border-bottom: 1px solid #dddddd; ">
<h4 style="font-size:30px; top: 90px;">Bengal Tiger</h4>
</div>

</section>

CSS CSS

.image { 
   position: relative; 

}

h4 { 
   position: absolute;    
   width: 100%; 
   color: #fff;
   float: left;   
   position: absolute;      
   font-size: 40px;
   font-family: "Oswald";
   text-align: center;
   max-height:auto;
   z-index:20;
   text-shadow:1px 1px 2px #000;
   -moz-text-shadow:1px 1px 2px #000;
   -ms-text-shadow:1px 1px 2px #000;
   -o-text-shadow:1px 1px 2px #000;
   -webkit-text-shadow:1px 1px 2px #000;

}

.image { 
   position: relative; 

}

.image:before{
content:'';
box-shadow:0 0 50px 4px #000 inset;
-moz-box-shadow:0 0 50px 4px #000 inset;
-webkit-box-shadow:0 0 50px 6px #000 inset;
float:left;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
z-index:20;
cursor: pointer;

}

.image:hover:before {
    box-shadow:0 0 100px 30px #000 inset;
    -moz-box-shadow:0 0 100px 30px #000 inset;
    -webkit-box-shadow:0 0 100px 30px #000 inset;
    transition: all 1s;
    -webkit-transition: all 1s;
}

How about something like this: 这样的事情怎么样:

.image:hover h4 {
    margin-top: -50px;
}

FIDDLE 小提琴

The text is placed absolutely relative to the div.image element using top:90px . 使用top:90px将文本绝对相对于div.image元素放置。 Adding padding at the bottom will not change this, it will only add some padding below the text. 在底部添加填充不会改变它,它只会在文本下面添加一些填充。 You can see this if you add a visible border to the text. 如果为文本添加可见边框,则可以看到此内容。

The easiest way to handle this is to change the top position of the text when the mouse hovers the image. 处理此问题的最简单方法是在鼠标悬停图像时更改文本的顶部位置。 See the udpated fiddle . 看到udpated小提琴

NOTE: I've only updated the first image so that you can compare the two elements to see the difference. 注意:我只更新了第一张图片,以便您可以比较这两个元素以查看差异。

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

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