在
Pure CSS: Center Tooltip Above Text On Hover上扩展 – 如果工具提示比所述容器宽,如何使工具提示悬停相对于其容器居中?
http://jsbin.com/idudal/24/edit
IE浏览器.这(拖动拖动阻力被切断):
应该显示为:
HTML:
<span id="test" class="drag-hint"><span>drag drag drag drag drag</span>Hover me</span>
CSS:
.drag-hint { position:relative; margin: 50px; } .drag-hint > span { background: black; color: white; white-space: Nowrap; display:none; } .drag-hint:hover > span { display: inline; position:absolute; top: -25px; left: 0; right: 0; text-align: center; }
解决方法
这是使用CSS3转换的最简单的解决方案.
.drag-hint { position: relative; margin: 50px; display: inline-block; padding: 0 1em; border: 1px solid red; /* for visual reference */ } .drag-hint > span { background: black; color: white; white-space: Nowrap; display: none; } .drag-hint:hover > span { display: inline-block; position: absolute; top: -25px; left: 50%; transform: translateX(-50%); text-align: center; }
<span class="drag-hint"> <span>drag drag drag drag drag</span> Hover me</span> <span class="drag-hint"> <span>Lorem ipsum dolor sit amet,consectetur adipisicing elit.</span> Hover me</span>