html - 我如何悬停图标并显示输入
问题描述
<div id='searchParent'>
<!--icon to be hovered-->
<i id="search" class="fas fa-search"></i>
<!--icon to be hovered-->
<div id="inputParent">
<!--input to be shown-->
<input type="text" placeholder='Pesquise' autocomplete='off' id="input-bar">
<!--input to be shown-->
</div>
</div>
我已经在这方面工作了很长时间,我能得到的最好的 CSS 悬停是:
#search:hover ~ #inputParent #input-bar {
width: 200px;
}
但问题是,当您将输入悬停时,它只是将其拖出,您不能只写任何东西。图标在我的本地机器上,但我可能会把它们放在那里
编辑:我将展示我的一些糟糕的 CSS 以及我打算做什么。
input {
border: none;
outline: none;
border-bottom: 0.3px solid black;
}
#search {
padding-left: 180px;
display: inline-block;
}
#inputParent {
margin-left: auto;
}
#input-bar {
margin-right: 1vw;
width: 0;
transition: 0.8s ease-in-out;
}
#search:hover ~ #inputParent #input-bar {
width: 200px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
</head>
<body>
<div id="searchParent">
<i id="search" class="fas fa-search"></i>
<div id="inputParent">
<input type="text" placeholder="Pesquise" autocoplete="off" id="input-bar">
</div>
</div>
</body>
</html>
我真正想做的是,当我将输入悬停时,它会留在那里。我真的不知道为什么酒吧是从左到右的,应该是倒退的
解决方案
嗨,如果您能够向您的 HTML 添加一个新的 div 并向您的 HTML 添加一个类,inputParent
这很容易。请看我的代码:
.dropdown {
position: relative;
display: inline-block;
}
#inputParent {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover #inputParent {
display: block;
}
<div id='searchParent'>
<!--icon to be hovered-->
<div class="dropdown">
<i id="search" class="fas fa-search"></i>Icon
<!--icon to be hovered-->
<div id="inputParent" class="parentc">
<!--input to be shown-->
<input type="text" placeholder='Pesquise' autocomplete='off' id="input-bar">
<!--input to be shown-->
</div>
</div>
</div>
推荐阅读
- java - 如果年龄低于 50,则更改行颜色
- apache-camel - 两个独立代理上的 Artemis 客户端负载平衡
- python - 如何在单行中输入不同的数据类型?
- java - 使用 mybatis 跨数据库检索值列表
- powershell - 从用户配置文件位置 NTUSER.DAT 读取映射驱动器
- c# - 弹性搜索滚动使用 Nest C# 获取所有记录需要太多时间
- angular - 延迟 ngFor 循环
- ruby - Ruby Fiddle - 在 WINdows MSYS2 中找不到函数
- javascript - 简单的 Google 脚本电子邮件应用程序 - 来自 Javascript 的 POST 请求失败
- python - 在 Google Colab 中使用 JupyterDash 加载外部样式表