纯CSS:悬停文字上方的中心工具提示pt。 2 [英] Pure CSS: Center Tooltip Above Text On Hover pt. 2

查看:112
本文介绍了纯CSS:悬停文字上方的中心工具提示pt。 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扩展



  .drag-hint {position:relative;边距:50px;显示:inline-block;填充:0 1em;边框:1px纯红色; / *以供参考* /}。drag-hint>跨度{背景:黑色;白颜色;空白:nowrap; display:none;}。drag-hint:hover>跨度{display:inline-block;位置:绝对;顶部:-25px;左:50%;转换:translateX(-50%); text-align:center;}  

 < span class = 拖曳提示> < span>拖动拖动拖动拖动< / span>将鼠标悬停在< / span>< span class = drag-hint> < span& Lorem ipsum dolor坐着,安全地服从精英。 > 

Expanding on Pure CSS: Center Tooltip Above Text On Hover -- how does one make the tooltip hover centered relative to its container if the tooltip is wider than said container?

http://jsbin.com/idudal/24/edit

Ie. this (where drag drag drag gets cut off):

Should appear as:

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;
}

解决方案

Here's the simplest solution using CSS3 transform.

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>

这篇关于纯CSS:悬停文字上方的中心工具提示pt。 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆