10

So I got a sketch of a designer I worked with and was wondering how I create the border arrows in the picture below

borderarrow

I tried to put out this font-awesome icon by using the :after selector, it got pretty ugly: http://fortawesome.github.io/Font-Awesome/icon/angle-right/

So instead, I tried to put an arrow on an arrow through this arrow generator: http://apps.eky.hk/css-triangle-generator/

It also became very ugly. So now I wonder if there is anyone who has a good idea on how to solve this?

How my html look like so far:

<div class="bx-pager bx-default-pager">

  <div class="bx-pager-item">
    <a class="bx-pager-link active" data-slide-index="0" href=""> 1. DIN EXPERT </a>
  </div>

  <div class="bx-pager-item">
    <a class="bx-pager-link" data-slide-index="1" href=""> 2. VÅRA TJÄNSTER </a>
  </div>

  <div class="bx-pager-item">
    <a class="bx-pager-link" data-slide-index="2" href=""> 3. CASE </a>
  </div>

  <div class="bx-pager-item">
    <a class="bx-pager-link" data-slide-index="3" href=""> 4. KONTAKT </a>
  </div>
</div>
Johan Nordli
  • 1,220
  • 3
  • 13
  • 26

5 Answers5

15

You can create triangles with CSS borders by:

border-top: 20px solid transparent; 
border-bottom: 20px solid transparent; /* 40px height (20+20) */
border-left: 20px solid green

I've created the same thing as you see above here:

#container {
  width:150px;
  height:40px;
  background-color:green;
  position:relative;
}
    
.arrow-right {
  width: 0; 
  height: 0; 
  border-top: 20px solid transparent; 
  border-bottom: 20px solid transparent; /* 40px height (20+20) */
  border-left: 20px solid green;
  position:absolute;
  right:-20px;
}
<div id="container">
  <div class="arrow-right"></div>
</div>
Daan
  • 2,680
  • 20
  • 39
10

Atlast!! :)

div.main {
    margin-right:30px;
}
ol > li {        
    display: table-cell;
    height: 30px;        
    position: relative;
    padding: 0px;
    margin: 0px;
    text-align: center;
    border: 1px solid #d68a3a;
}
ol > li > div {         
    position:relative;        
    line-height: 30px; /* equal to the list item's height */
    height:100%;
    width: 100%;         
}
ol>li:hover {
    background-color: #d68a3a;
    cursor: pointer;
    color: white;
}
ol {
    display: table;
    width: 100%;
    padding: 0px;
    margin: 0px;
    position: relative;
}
ol > li > div:after, ol > li > div:before {
    content:"";
    display:inline-block;        
    border-width: 16px;
    border-style: solid;
    width: 0px;
    height: 0px;
    left: 100%;
    top: -1px;        
    position: absolute;        
    z-index: 1;
}
ol > li > div:after, ol > li:hover > div:before {
    border-color: transparent transparent transparent #d68a3a;
}
ol > li > div:before {
    border-width: 14px;
    display: block;
    border-color: transparent transparent transparent #ffffff;
    z-index: 2;
    top:1px;
}

Working Fiddle

Mr_Green
  • 40,727
  • 45
  • 159
  • 271
  • There might be arrow adjustment issues, which you can fix by changing values to `left`, `margin-right` and `border-width`. – Mr_Green May 02 '14 at 13:19
  • Working only in Chrome :( – Mr_Green May 02 '14 at 13:30
  • thanks for the reply! It works very nicely, but unfortunately only on webkit based browsers: ( – Johan Nordli May 02 '14 at 13:43
  • @JohanNordli Updated my post. that was actually a [bug in firefox](http://stackoverflow.com/a/8312358/1577396). which I fixed now. – Mr_Green May 02 '14 at 15:47
  • can't believe why there was so much trouble relating to a simple-like problem, your demo worked OK in webkit-based browsers **and IE**, but now it works OK in webkit-based browsers **and FireFox**, IE renders it much worse. – King King May 02 '14 at 15:51
  • @KingKing if I give `top: 57%` id does look good even in IE8. but not a ideal solution. I couldn't find what could be the problem. – Mr_Green May 02 '14 at 16:01
  • @Mr_Green you can't fix it that way, because the code should be considered to run OK in all browsers without any have-fix for a particular browser. However I've tried digging into your demo and found that you used `margin-top` to offset the triangles, which should not be used. You should use `top` instead and remember that it is relative to the `div`, so your `div` should also be aligned to the top of the `li`, you can do that by setting its `height` to `100%` (which you've not done), here is the [updated demo](http://jsfiddle.net/LTt2e/11/) which **works OK** on all browsers. – King King May 02 '14 at 16:35
  • BTW, I doubt that you don't need any div, just use the `:before` and `:after` right on the `li`. – King King May 02 '14 at 16:37
  • @KingKing yeah I did that earlier. found later that there is a serious bug in firefox related to `display: table-cell` and `position: relative`. The suggestion was to add a div wrapper. I mentioned the link in [above comments](http://stackoverflow.com/questions/23428286/create-border-arrow-with-css/23429132?noredirect=1#comment35911974_23429132). BTW, thanks for the fiddle :) I was actually planning to avoid line-height as that will not work for two line contents.. I think there is no other way.. – Mr_Green May 02 '14 at 17:08
  • 1
    @Mr_Green I think it suits the OP's situation (in which the text should be on a single line). Even if your original demo worked, to make it work with **multiline** requires many fixes, the triangle size is set fixedly at `16px`, ... when there are more than 1 line, the triangle size should be also dynamically changed accordingly ... Anyway, supporting multiline is a more complicated problem. – King King May 02 '14 at 17:16
6

You have to make little bit changes to your html structure

  1. Put active class at bx-pager-item element level
  2. Put 1 extra element after anchor tag .

Please refer below code snippet.

Working fiddle link: Fiddle

.container {
  max-width: 700px;
  margin: auto;
}

.bx-pager {
  display: flex;
  align-items: center;
  height: 34px;
  border-left: 1px solid #d68a3a;
}
.bx-pager .bx-pager-item {
  display: flex;
  align-items: center;
  height: 100%;
  flex: 0 25%;
  border-top: 1px solid #d68a3a;
  border-bottom: 1px solid #d68a3a;
}
.bx-pager .bx-pager-item .bx-pager-link {
  text-decoration: none;
  color: #222;
  font-size: 13px;
  flex: 1;
  padding-left: 16px;
  text-align: center;
}
.bx-pager .bx-pager-item .arrow {
  border: solid #d68a3a;
  display: inline-block;
  padding: 9px;
  border-width: 0 1px 1px 0;
  transform: translateY(15.5px) rotate(-45deg) skew(-15deg, -15deg) translateX(18px);
  background-color: #FFF;
}
.bx-pager .bx-pager-item.active {
  background-color: #d68a3a;
}
.bx-pager .bx-pager-item.active .bx-pager-link {
  color: white;
}
.bx-pager .bx-pager-item.active .arrow {
  background-color: #d68a3a;
}
<body>

  <div class="container">


    <div class="bx-pager bx-default-pager">

      <div class="bx-pager-item active">
        <a class="bx-pager-link " data-slide-index="0" href=""> 1. DIN EXPERT </a>
        <div class="arrow">

        </div>
      </div>

      <div class="bx-pager-item">
        <a class="bx-pager-link" data-slide-index="1" href=""> 2. VÅRA TJÄNSTER </a>
        <div class="arrow">

        </div>
      </div>

      <div class="bx-pager-item">
        <a class="bx-pager-link" data-slide-index="2" href=""> 3. CASE </a>
        <div class="arrow">

        </div>
      </div>

      <div class="bx-pager-item">
        <a class="bx-pager-link" data-slide-index="3" href=""> 4. KONTAKT </a>
        <div class="arrow">

        </div>
      </div>
    </div>
  </div>
</body>
Jignesh Thummar
  • 161
  • 2
  • 6
2

Please Change according to your specification.

<style>
.menu {
    position: relative;
    background: #88b7d5;

    width:150px;
    height:60px;
}
.menu:after, .menu:before {
    left: 100%;
    top: 50%;
    border: solid transparent;
    content: " ";
    height: 0px;
    width: 0px;
    position: absolute;
    pointer-events: none;
}

.menu:after {
    border-color: rgba(136, 183, 213, 0);
    border-left-color: #88b7d5;
    border-width: 30px;
    margin-top: -30px;
}
</style>

<div class="menu">
</div>
King King
  • 61,710
  • 16
  • 105
  • 130
Shehroz Asmat
  • 161
  • 14
2

In case it is needed for others here is another solution, that can work as the requested answer, but will work if there is a need of separation of the elements.

Using the above examples, what will happen is that the background must always remain the same color. Like this it will always have a separation thus transparency between items.

Hope this helps, this post really helped me to find this solution :)

.items--container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  margin-left: 1rem;
  width: 150px;
  height: 50px;
}

.item.active .content {
  color: #FFFFFF;
}

.item.active .arrow {
  background: #d68a3a;
}

.content {
  color: #000000;
  position: absolute;
  z-index: 2;
}

.arrow {
  width: 100%;
  height: 50%;
  background: #FFFFFF;
}

.arrow.top {
  transform: skew(45deg, 0deg);
  border-left: 1px solid #d68a3a;
  border-right: 1px solid #d68a3a;
  border-top: 1px solid #d68a3a;
}

.arrow.bottom {
  transform: skew(-45deg, 0deg);
  border-left: 1px solid #d68a3a;
  border-right: 1px solid #d68a3a;
  border-bottom: 1px solid #d68a3a;
}
<div class="items--container">
  <div class='item'>
    <div class="arrow top"></div>
    <div class="content">Menu Item 1</div>
    <div class="arrow bottom"></div>
  </div>
  <div class='item'>
    <div class="arrow top"></div>
    <div class="content">Menu Item 2</div>
    <div class="arrow bottom"></div>
  </div>
  <div class='item active'>
    <div class="arrow top"></div>
    <div class="content">Menu Item 3</div>
    <div class="arrow bottom"></div>
  </div>
  <div class='item'>
    <div class="arrow top"></div>
    <div class="content">Menu Item 4</div>
    <div class="arrow bottom"></div>
  </div>
</div>
Rip3rs
  • 1,284
  • 12
  • 21