gpt4 book ai didi

html - 将鼠标悬停在图像上时显示按钮(rails image_tag)

转载 作者:太空宇宙 更新时间:2023-11-03 18:45:59 24 4
gpt4 key购买 nike

这是我正在尝试做的事情:显示来 self 的数据库的图像,并在将鼠标悬停在图像上时在图像顶部显示带有下载按钮(链接到文件的 URL)的叠加层。参见此处的插图:http://cl.ly/image/2T200Z451K0v

我正在使用 rails 和回形针。这基本上是我的看法:

<%= image_tag pin.image(:medium) %>
<%= link_to "download", pin.download_link, class: "btn btn-large btn-primary"%>

下面显示图片和下载按钮。

我已经尝试了很多方法,我已经设法让按钮仅在我将鼠标悬停在图像上时出现,但按钮始终位于图像下方。我尝试使用 position:relative 但我想如果图像是一个 div 并且按钮在该 div 中它会起作用但我不知道该怎么做。

最佳答案

使用 HTML 和 CSS 很容易做到这一点。这是一个例子:

http://codepen.io/anon/pen/Hwfnz

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<style media="all">
div {width: 300px; height: 240px;}

a {display: table; width: 300px; height: 240px; vertical-align: middle; text-align: center; position: relative;}

span {display: none;}

a:hover span {width: 300px; height: 240px; line-height: 240px; position: absolute; left: 0; top: 0; display: block; text-align: center; background: rgba(67,81,96,0.7); }

span b {font-size: 1.5em; font-weight: normal; padding: 8px 12px; border-radius: 5px; background: #6bbe70; color: #fff; font-family: sans-serif;}

a:hover span b:hover {background: #000;}

img {background: #e7e7e7; border: none; vertical-align: bottom;}
</style>

</head>
<body>

<div>
<a href=""><img src="http://pageaffairs.com/sp/so-16390475.jpg" width="300" height="240"> <span><b>download</b></span></a>
</div>

</body>
</html>

关于html - 将鼠标悬停在图像上时显示按钮(rails image_tag),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com