在工具提示中显示的 div 顶部添加一个三角形?

Cha*_*kar 5 html css

我有一个 div,它将显示在某个元素的悬停上。当我们将鼠标悬停在元素上时将显示的 div 显示在元素下方。我需要/\使用 css将三角形添加到 div 的顶部。

我怎样才能做到这一点?

HTML

<div class="user-options">
        <ul class="settings">
            <li><a href="home.html">JOHN DOE</a></li>
            <li><a href="user-customization.html">My Playground</a></li>
            <li><a href="myrules.html">Settings</a></li>
            <li><a href="index.html">Logout</a></li>
        </ul>
    </div>
Run Code Online (Sandbox Code Playgroud)

CSS

.user > .user-options {
    background: none repeat scroll 0 0 #eeeeee;
    display: none;
    margin-top: 25px;
    overflow: auto;
    padding: 0 0 0 10px;
    position: absolute;
    width: 125px;
    z-index: 999;
    border:solid #cccccc 1px;
    margin-left:-24px;
}
Run Code Online (Sandbox Code Playgroud)

Luí*_* A. 3

你可以这样做:

注意:删除overflow: auto;来自.user-options

CSS

.user-options {
    background: none repeat scroll 0 0 #eeeeee;
    margin-top: 25px;
    padding: 0 0 0 10px;
    position: absolute;
    width: 125px;
    z-index: 999;
    border:solid #cccccc 1px;
    margin-left:-24px;
}

.user-options:after, .user-options:before {
    bottom: 100%;
    left: 50%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}

.user-options:after {
    border-color: rgba(238, 238, 238, 0);
    border-bottom-color: #eeeeee;
    border-width: 15px;
    margin-left: -15px;
}
.user-options:before {
    border-color: rgba(204, 204, 204, 0);
    border-bottom-color: #cccccc;
    border-width: 16px;
    margin-left: -16px;
}
Run Code Online (Sandbox Code Playgroud)

演示在这里