Create border arrow with css

前端 未结 5 2209
清歌不尽
清歌不尽 2020-12-06 20:18

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

相关标签:
5条回答
  • 2020-12-06 20:33

    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>

    0 讨论(0)
  • 2020-12-06 20:33

    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

    0 讨论(0)
  • 2020-12-06 20:40

    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>
    
    0 讨论(0)
  • 2020-12-06 20:42

    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>

    0 讨论(0)
  • 2020-12-06 20:43

    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>

    0 讨论(0)
提交回复
热议问题