gpt4 book ai didi

html - Jquery Image on Hover制作输入类型文件

转载 作者:太空狗 更新时间:2023-10-29 14:51:01 24 4
gpt4 key购买 nike

当我将鼠标悬停在图像上时,图标会显示。但是我想这样显示图标

当我点击时,它应该允许浏览像这样的文件 enter image description here

<input type ='file'>

我该怎么做?

我试过将文件标签放在所有文件中,但没有用。我该怎么做?

.profile-img-container {
position: absolute;
width:50%;
}

.profile-img-container img:hover {
opacity: 0.5;
z-index: 501;
}

.profile-img-container img:hover + i {
display: block;
z-index: 500;
}

.profile-img-container i {
display: none;
position: absolute;
margin-left:43%;
margin-top:40%;
}

.profile-img-container img {
position:absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

<div class="profile-img-container">
<img src="http://s3.amazonaws.com/37assets/svn/765-default-avatar.png" class="img-thumbnail img-circle img-responsive" />
<i class="fa fa-upload fa-5x"></i>
</div>

Fiddle

最佳答案

您需要在您的代码中添加一个input[type="file"] 并使其不可见。此外,它占据了所有 img 位置,将其 position 设置为 absolute 和所有其他样式,因此它占据了所有位置。

像这样:

.profile-img-container {
position: absolute;
/*width:50%;*/
/*border-radius:50%;*/
overflow:hidden;
}

.profile-img-container img:hover {
opacity: 0.5;
z-index: 501;
}

.profile-img-container img:hover + i {
display: block;
z-index: 500;
}

.profile-img-container .icon-wrapper {
position: absolute;
bottom:0;
left:0;
background:rgba(0,0,0,0.7);
color:#fff;
text-align:center;
width:100%;
padding:5px;
}

/*.profile-img-container img {
position:absolute;
}*/

/*.profile-img-container {
position:relative;
}*/

input[type="file"] {
opacity:0;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

<div class="profile-img-container img-circle">
<input type="file" />
<img src="http://s3.amazonaws.com/37assets/svn/765-default-avatar.png" class="img-thumbnail img-circle img-responsive" />
<div class="icon-wrapper">
<i class="fa fa-upload fa-5x"></i>
</div>
</div>

关于html - Jquery Image on Hover制作输入类型文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35265208/

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