纯CSS:中心工具提示高于文本悬停pt. 2

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转换的最简单的解决方案.

JSfiddle Demo

.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>

相关文章

Css3如何实现鼠标移上变长特效?(图文+视频)
css3怎么实现鼠标悬停图片时缓慢变大效果?(图文+视频)
jquery如何实现点击网页回到顶部效果?(图文+视频)
css3边框阴影效果怎么做?(图文+视频)
css怎么实现圆角边框和圆形效果?(图文+视频教程)
Css3如何实现旋转移动动画特效