Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a triangle to the top of div as it appears in tooltip? [duplicate]

Tags:

html

css

I have the div which will be shown on hover of some element. the div which will display when we hover on element is displayed below the element. I need to add the triangle /\ to the top of div using css.

How can I achieve this?

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>

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;
}
like image 390
CJAY Avatar asked Sep 28 '22 01:09

CJAY


1 Answers

You can do it like this:

Note: remove the overflow: auto; from .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;
}

DEMO HERE

like image 66
Luís P. A. Avatar answered Oct 20 '22 09:10

Luís P. A.