Search code examples
csshtmlcss-shapes

Draw triangle on right-border


I have a ul element with many li. Some lines (li) are highlighted with yellow background.

I want to add a triangle to the right border. This triangle should looks like an arrow that point to the text.

Something like this: enter image description here

Fiddle

I tried to draw this triangle with right border, but this not giving me the right shape.

<ul>
    <li>not highlighted</li>
    <li>not highlighted</li>
    <li class="highlighted">HIGHLIGHTED</li>
    <li>not highlighted</li>
</ul>
<style>
.highlighted {
    border-right: 20px solid red;
}
</style>

Please give a notice on the that one li can contain more the one line, so the height of the line can be changed. Arrow with fixed height (of one line) is good enough.

Is this possible? If yes, how?


Solution

  • This should do it (but I doubt you can get outlined arrow without an image - only full).

    .highlighted:after {
      content: "";
      position: absolute;
      right: 0;
      width: 0;
      height: 0;
      border-top: 10px solid transparent;
      border-bottom: 10px solid transparent;
      border-right: 10px solid red;
    }
    <ul>
      <li>not highlighted</li>
      <li>not highlighted</li>
      <li class="highlighted">HIGHLIGHTED</li>
      <li>not highlighted</li>
    </ul>

    Based on this tutorial.