简体   繁体   English

使用Javascript和CSS定位弹出窗口

[英]Pop-up window positioning with Javascript and CSS

My web application has a search field where user can enter some tags to search by. 我的Web应用程序有一个搜索字段,用户可以在其中输入一些标签进行搜索。 The window should pop-up just under the search field, like in the picture below: 该窗口应在搜索字段下方弹出,如下图所示: 弹出窗口示例

The main detail I need to understand is how is the window positioning implemented. 我需要了解的主要细节是如何实现窗口定位。 Is it some hidden div with absolute positioning and z-index? 它是具有绝对位置和z-index的隐藏div吗? I am interested in the most common Vanilla Javascript, HTML5, and CSS approaches. 我对最常用的Vanilla Javascript,HTML5和CSS方法感兴趣。

The suggestion box is an autocomplete component. 建议框是自动完成组件。 You could very well use the jQuery Token Input by James Smith ( http://loopj.com/jquery-tokeninput/ ) 您可以很好地使用James Smith( http://loopj.com/jquery-tokeninput/ )的jQuery令牌输入

As far as the position curiosity: 就职位好奇心而言:

It's just a matter of alignment to the bottom of the input element. 这只是与输入元素的底部对齐的问题。 That can be done using pure CSS. 可以使用纯CSS完成。

 input { width: 50%; } .spanClass { display: none; } .focusAlign input[type="text"]:focus~.spanClass { display: block; width: 50%; box-sizing: border-box; position: absolute; top: 29px; left: 8px; background: #333; padding: 3px; font: .75em sans-serif; color: #eee; } 
 <div class="focusAlign"> <input id="same" type="text" value="" /> <span class="spanClass"> <p>Oh, this is a suggestion.</p> <p>Yeah, well, so am I.</p> <p>Me, too!</p> <p>Whatever, I'm here.</p> </span> </div> 

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

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