html - 在输入类型文本上显示 "small popup"的最佳方式

标签 html css

当我将鼠标放在输入类型的文本上时,我需要在小弹出窗口中显示一些信息。

目前我正在使用这样的标题应答器:http://jsfiddle.net/q8Lp0nLo/

<input type="text" size="5"><div>The text to show</div>

div{
    display:inline-block;
    visibility:hidden;
    position:absolute;
    background-color:#E5E5F0; color:black;
}
input[type="text"]:hover~ div{visibility:visible}

它在 chrome 上运行良好,但在 IE 上运行不佳。如果我完全填写输入,弹出窗口不会出现或出现并在几秒钟后隐藏。

制作这个的最佳方法是什么? : 完成

新问题:如何在鼠标位置旁边显示弹出窗口(我不需要在移动鼠标的同时移动弹出窗口,只需在第一个位置显示一次)。

实际代码:http://jsfiddle.net/q8Lp0nLo/

就像这个,但有弹出窗口:http://jsfiddle.net/BaDCe/

谢谢

最佳答案

试试这个:

/* tooltip */


.tool-tip{
	color: #fff;
	background-color: rgba( 0, 0, 0, .7);
	text-shadow: none;
	font-size: .8em;
	visibility: hidden;
	-webkit-border-radius: 7px; 
	-moz-border-radius: 7px; 
	-o-border-radius: 7px; 
	border-radius: 7px;	
	text-align: center;	
	opacity: 0;
	z-index: 999;
	padding: 3px 8px;	
	position: absolute;
	cursor: default;
	-webkit-transition: all 240ms ease-in-out;
	-moz-transition: all 240ms ease-in-out;
	-ms-transition: all 240ms ease-in-out;
	-o-transition: all 240ms ease-in-out;
	transition: all 240ms ease-in-out;	
}

.tool-tip,
.tool-tip.top{
	top: auto;
	bottom: 114%;
	left: 50%;		
}

.tool-tip.top:after,
.tool-tip:after{
	position: absolute;
	bottom: -12px;
	left: 50%;
	margin-left: -7px;
	content: ' ';
	height: 0px;
	width: 0px;
	border: 6px solid transparent;
    border-top-color: rgba( 0, 0, 0, .7);	
}

/* default heights, width and margin w/o Javscript */

.tool-tip,
.tool-tip.top{
	width: 80px;
	height: 22px;
	margin-left: -43px;
}

/* tool tip position right */

.tool-tip.right{
	top: 50%;
	right: auto;
	left: 106%;
	margin-top: -15px;
	margin-right: auto;	
	margin-left: auto;
}

.tool-tip.right:after{
	left: -5px;
	top: 50%;	
	margin-top: -6px;
	bottom: auto;
	border-top-color: transparent;	
    border-right-color: rgba( 0, 0, 0, .7);	
}

/* tool tip position left */

.tool-tip.left{
	top: 50%;
	left: auto;
	right: 105%;
	margin-top: -15px;	
	margin-left: auto;	
}

.tool-tip.left:after{
	left: auto;
	right: -12px;
	top: 50%;
	margin-top: -6px;
	bottom: auto;
	border-top-color: transparent;	
    border-left-color: rgba( 0, 0, 0, .7);	
}

/* tool tip position bottom */

.tool-tip.bottom{
	top: 115%;
	bottom: auto;
	left: 50%;
	margin-bottom: auto;	
}

.tool-tip.bottom:after{
	position: absolute;
	top: -12px;
	left: 50%;
	margin-left: -7px;
	content: ' ';
	height: 0px;
	width: 0px;
	border: 6px solid transparent;
    border-top-color: transparent;	
    border-bottom-color: rgba( 0, 0, 0, .6);	
}

/* tooltip on focus left and right */

.on-focus .tool-tip.left,
.on-focus .tool-tip.right{
	margin-top: -19px;
}

/* on hover of element containing tooltip default*/

*:not(.on-focus):hover > .tool-tip,
.on-focus input:focus + .tool-tip{
	visibility: visible;
	opacity: 1;
	-webkit-transition: all 240ms ease-in-out;
	-moz-transition: all 240ms ease-in-out;
	-ms-transition: all 240ms ease-in-out;
	-o-transition: all 240ms ease-in-out;
	transition: all 240ms ease-in-out;		
}


/* tool tip slide out */

*:not(.on-focus) > .tool-tip.slideIn,
.on-focus > .tool-tip{
	display: block;
}

.on-focus > .tool-tip.slideIn{
	z-index: -1;
}

.on-focus > input:focus + .tool-tip.slideIn{
	z-index: 1;
}

/* bottom slideIn */

*:not(.on-focus) > .tool-tip.slideIn.bottom,
.on-focus > .tool-tip.slideIn.bottom{
	top: 50%;	
}

*:not(.on-focus):hover > .tool-tip.slideIn.bottom,
.on-focus > input:focus + .tool-tip.slideIn.bottom{
	top: 115%;
}	

.on-focus > input:focus + .tool-tip.slideIn.bottom{
	top: 100%;
}

/* top slideIn */

*:not(.on-focus) > .tool-tip.slideIn,
*:not(.on-focus) > .tool-tip.slideIn.top,
.on-focus > .tool-tip.slideIn,
.on-focus > .tool-tip.slideIn.top{
	bottom: 50%;
}

*:not(.on-focus):hover > .tool-tip.slideIn,
*:not(.on-focus):hover > .tool-tip.slideIn.top,
.on-focus > input:focus + .tool-tip.slideIn,
.on-focus > input:focus + .tool-tip.slideIn.top{
	bottom: 110%;
}	

/* left slideIn */

*:not(.on-focus) > .tool-tip.slideIn.left,
.on-focus > .tool-tip.slideIn.left{
	right: 50%;	
}

*:not(.on-focus):hover > .tool-tip.slideIn.left,
.on-focus > input:focus + .tool-tip.slideIn.left{
	right: 105%;		
}

/* right slideIn */

*:not(.on-focus) > .tool-tip.slideIn.right,
.on-focus > .tool-tip.slideIn.right{
	left: 50%;		
}

*:not(.on-focus):hover > .tool-tip.slideIn.right,
.on-focus > input:focus + .tool-tip.slideIn.right{
	left: 105%;
}
<div style="width: 550px; margin: 0px auto;">
		<div style="clear:both;padding:20px;"></div>
		<div class="on-focus clearfix" style="position: relative; padding: 0px; margin: 10px auto; display: table; float: left">
			<input type="text" value="" name="try" placeholder="Tooltip right on focus" />
			<div class="tool-tip slideIn right">Tool Tip</div>
		</div>
		<div style="clear:both;"></div>
		<div class="on-focus clearfix" style="position: relative; padding: 0px; margin: 10px auto; display: table; float: left">
			<input type="text" value="" name="try" placeholder="Tooltip left on focus" />
			<div class="tool-tip slideIn left">Tool Tip</div>
		</div>		

		<div style="clear:both;"></div>
		<div class="on-focus clearfix" style="position: relative; padding: 0px; margin: 10px auto; display: table; float: left">
			<input type="text" value="" name="try" placeholder="Tooltip Top on focus" />
			<div class="tool-tip  slideIn">Tool Tip</div>
		</div>

		<div style="clear:both;"></div>
		<div class="on-focus clearfix" style="position: relative; padding: 0px; margin: 10px auto; display: table; float: left">
			<input type="text" value="" name="try" placeholder="Tooltip Bottom on focus" />
			<div class="tool-tip bottom  slideIn ">Tool Tip</div>
		</div>	
	</div>

来源:http://cssdeck.com/labs/tooltipscss3

关于html - 在输入类型文本上显示 "small popup"的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33009053/

相关文章:

html - 在柱形图中绘制两条线谷歌图表

html - React Helmet 不更新元标记

css - 有没有办法结合分支元素ID和向下箭头的元素ID?

html - 对齐主导航产品类别

javascript - JSFiddle 下拉按钮不可点击

css - 使某个图像不受 img css 影响

html - 当视口(viewport)宽度低于 225px 时网格单元突出

PHP - 浏览器不缓存动态图像

html - 使用flask从html输入到mysql;只接受单字符输入

javascript - Web 浏览器上的 SVG 和音频