【问题标题】:Border issue with tooltip react js工具提示反应js的边框问题
【发布时间】:2021-01-12 20:28:21
【问题描述】:

我创建了一个工具提示,需要为其设置边框颜色,但它给了我一个错误 下图供参考。

image

工具提示代码

.mytooltip {
    position: absolute;
    padding: 5px;
    border: 1px solid gray;
    background-color: #ffffff;
    color: $color-black;
    min-width: 50px;
    opacity: 0;
    transition-property: opacity, transform;
    transform-origin: center center;
    text-align: center;

    &:after {
        border: 1px solid;
        border-width: 6px;
        content: '';
        height: 0;
        position: absolute;
        width: 0;
    }
}

底部方向码

.mytooltip--bottom {
    transform: translate(-50%, 15px) scale(0);

    &:after {
        border-color: black;
        border-bottom-color: #ffffff;
        bottom: 100%;
        left: 50%;
        margin-left: -6px;
    }
}

请帮我解决这个问题

【问题讨论】:

  • 能否也添加相关的HTML代码?
  • 我正在使用 react js

标签: css reactjs sass


【解决方案1】:

你需要使用两个伪元素。

.mytooltip {
    position: absolute;
    padding: 5px;
    border: 1px solid gray;
    background-color: #ffffff;
    color: #000000;
    min-width: 50px;
    transform-origin: center center;
    text-align: center;
}
.mytooltip:after,
.mytooltip:before {
    border: 1px solid;
    border-width: 6px;
    content: '';
    height: 0;
    position: absolute;
    width: 0;
}
.mytooltip--bottom:before {
    border-color: transparent;
    border-bottom-color: gray;
    bottom: 101%;
    left: 50%;
    margin-left: -7px;
    border-width: 7px;
}
.mytooltip--bottom:after {
    border-color: transparent;
    border-bottom-color: #ffffff;
    bottom: 100%;
    left: 50%;
    margin-left: -6px;
}
<div class="mytooltip mytooltip--bottom">this is it!!</div>

【讨论】:

  • 请检查 - mytooltipmytooltip--bottom 在同一个元素上
猜你喜欢
  • 2016-12-23
  • 1970-01-01
  • 2023-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多