【问题标题】:CSS tooltip with arrow and border [duplicate]带有箭头和边框的 CSS 工具提示 [重复]
【发布时间】:2016-08-20 17:04:18
【问题描述】:

我正在尝试使用白色背景颜色和 1px 边框的 CSS 工具提示。 如何用边框代替纯黑色箭头?

.up-arrow {
    display: inline-block;
    position: relative;
    border: 1px solid #777777;
    text-decoration: none;
    border-radius: 2px;
    padding: 20px;
}
.up-arrow:after {
    content: '';
    display: block;  
    position: absolute;
    left: 140px;
    bottom: 100%;
    width: 0;
    height: 0;
    border-bottom: 10px solid black;
    border-top: 10px solid transparent;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
}
<div href="#" class="up-arrow">Button with Up Arrow</div>

PS:即使看起来与另一个问题相似,设计的细节也很重要。例如,这里最初有 3 个不同的答案(现在删除了其中的 2 个),设计略有不同。即使差别不大,他们的箭头看起来也没有当前完美答案那么完美!魔鬼在细节中!
这里的目标是有一个纯白色的工具提示,带有 1px 宽的边框。即使看起来与其他问题相似,它也不是其他问题(讲话泡泡)的重复。再次强调细节对于打造如此时尚的外观非常重要。

【问题讨论】:

  • @jbutler483 :这是一个很接近的问题,但显然不是重复的。
  • 我的回答包括为此类工具提示添加边框。如果您认为您的问题不是,请编辑您的问题以清楚地阐明差异。
  • 这是一个骗子@Basj。结果是完全一样的,你只是把箭头放在不同的位置...
  • @Basj 它是重复的,因为它是完全相同的形状,只是位置不同。被骗的那个(已经存在的时间更长并且有更多的赞成票)只有一个双边框(简单的 css 更改)和灰色背景(另一个简单的 css 更改)。尽管下面的答案可能是完美的,但如果您花了 2 分钟时间尝试使用受骗的答案,您将获得完全相同的结果。
  • jsfiddle.net/Lyae1v0L/2 - 这取自链接的示例代码,改动很小

标签: css tooltip css-shapes


【解决方案1】:

其中一个解决方案是添加另一个伪元素:before,它比:after 略小。这不是有史以来最好的解决方案,但它在特定情况下工作得非常好。

(您可能会注意到我还稍微清理了您的代码并将:after 替换为:before 以便为两个伪元素提供正确的z-index。如果您需要进一步解释,请告诉我)

.up-arrow {
    display: inline-block;
    position: relative;
    border: 1px solid #777777;
    text-decoration: none;
    border-radius: 2px;
    padding: 20px;
    margin-top: 50px;
}
.up-arrow:before {
    content: '';
    display: block;  
    position: absolute;
    left: 140px;
    bottom: 100%;
    width: 0;
    height: 0;
    border: 10px solid transparent;
    border-bottom-color: black;
}

.up-arrow:after {
    content: '';
    display: block;  
    position: absolute;
    left: 141px;
    bottom: 100%;
    width: 0;
    height: 0;
    border: 9px solid transparent;
    border-bottom-color: white;
}
<div href="#" class="up-arrow">Button with Up Arrow</div>

【讨论】:

  • 如何让它从上到下指向?
  • 您需要在我的高 DPI 屏幕上执行以下操作,以校正三角形和框之间的 1/2 像素细线:.up-arrow:after { bottom: calc(100% - 0.5px); } 这也使三角形周围的边框宽度相同厚度为框周围的 1px 边框。
猜你喜欢
  • 2012-09-20
  • 1970-01-01
  • 2019-09-07
  • 2014-12-04
  • 2019-05-03
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多