Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css triangle at the end of <li>

I want to achieve something like this enter image description here

How do I put this triangle css

    .triangle{
width: 0;
height: 0;
border-style: solid;
border-width: 21px 42px 21px 0;
border-color: transparent #eeeeee transparent transparent;
line-height: 0px;
_border-color: #000000 #eeeeee #000000 #000000;
_filter: progid:DXImageTransform.Microsoft.Chroma(color='#000000');
    }

to make a triangle at the end of my tab? DEMO http://jsfiddle.net/p69qfqsx/

like image 854
Elton Jamie Avatar asked Mar 25 '15 02:03

Elton Jamie


People also ask

How do I add a triangle to a div in CSS?

Add a triangle to end of div You can use :after selector to add a style to the end of a div. When adding an arrow to bottom we need to keep the top border and make other borders transparent. In this div, the width has been set as 100px. Then the left and the right border have to be half of size of the div.

How do CSS triangles work?

The concept is to create a box with no width or height. The width of the border determines the Triangle's actual width and height. The bottom border of an up-arrowed triangle, for example, is colored, while the left and right borders are transparent, forming a triangle.


2 Answers

New CSS for the list:

ul{
    width: 200px;
    border: 1px solid #ccc;
}

li a{
    background-color: #fff;
    padding: 5px 10px;
    display: block;
    position: relative;
    color: #666;
    text-decoration: none;
}

li a:hover, li.active a{
    background-color: #eee;
}

li a:hover:after, li.active a:after{
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid #fff;
  /* background-color: #ddd; */
  content: '';
  position: absolute;
  right: -2px;
  top: 0;
}

https://jsfiddle.net/p69qfqsx/2/

Tested just for chrome hope it helps.

like image 141
André Morales Avatar answered Sep 30 '22 12:09

André Morales


Here's the codes I modify for little change:

li a:hover:after{
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 12px solid transparent;
  border-right: 10px solid #fff;
  /* background-color: #ddd; */
  content: '';
  position: absolute;
  right: -2px;
  top: 1;
}

I just remove li.active a:after to let pointer makes it. DEMO
But I prefer using what @Andre Morales suggest since it works here.

like image 31
Joe Kdw Avatar answered Sep 30 '22 14:09

Joe Kdw