How to make angled tab like this using css?
Asked Answered
L

6

21

I need to make like this. Is it possible with pure css?

enter image description here

Laubin answered 17/1, 2012 at 13:19 Comment(0)
N
19

Using border-radius, :before and transform: skew(...);

body {
  background-color: #000;
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  font-size: 16px;
}
.tab {
  height: 50px;
  width: 150px;
  border-radius: 15px 15px 0px 0px;
  background-color: #FFF;
  position: relative;
  top: 10px;
  left: 1px;
  display: inline-block;
  z-index: 2;
}
.tab:before {
  height: 50px;
  width: 70px;
  border-radius: 10px 10px 0px 0px;
  background-color: white;
  content: "";
  position: absolute;
  left: 104px;
  top: 0px;
  -webkit-transform: skewX(40deg);
  transform: skewX(40deg);
  z-index: -1;
}
.tab:nth-of-type(2) {
  background-color: #555;
  top: 10px;
  left: 30px;
  z-index: 1;
  color: #EEE;
}
.tab:nth-of-type(2):before {
  background-color: #555;
}
.tab:nth-of-type(2):hover,
.tab:nth-of-type(2):hover:before {
  background-color: #159;
  transition: 0.3s ease-out;
}
span {
  display: inline-block;
  width: 160px;
  text-align: center;
  height: 50px;
  line-height: 50px;
  z-index: 3;
}
#page {
  background-color: white;
  height: calc(100vh - 120px);
  width: calc(100vw - 61px);
  position: relative;
  top: 10px;
  left: 1px;
  padding: 30px;
}
<nav id="tabs">
  <div class="tab">
    <span>Tab 1</span>
  </div>
  <div class="tab">
    <span>Tab 2</span>
  </div>
</nav>
<div id="page">
  Lorem Ipsum dolor sit amet ...
</div>
Niobium answered 16/1, 2015 at 13:24 Comment(0)
S
7

With CSS3, use border-radius to make the curved tab corner, then create a triangle with a lower z-index.

The HTML:

<div class="tab">
    <div class="arrow"></div>
</div>

The CSS:

body
{
    background-color: #666;    
}
.tab
{
    height: 50px;
    width: 150px;
    border-radius: 10px 10px 0px 0px;
    background-color: #FFF;
    position: relative;
}

.arrow
{
  border-color: transparent transparent #FFF #FFF;
  border-style: solid;
  border-width: 23px 23px 23px 23px;
  height:0;
  width:0;
  position:absolute;
  bottom:0px;
  right:-43px;
}

The result: http://jsfiddle.net/P3P3Z/2/

It's not perfect and it may render differently on different browsers, but should get you started. :) Some things have to be tweaked a little so it looks nice.

Sunfast answered 17/1, 2012 at 13:51 Comment(1)
Thanks :) I've been using the technique extensively since it allows for background-color animation with jQuery. So you can fade both box and triangle at the same time.Sunfast
A
2

This question intrigued me so here is a working example.

<html>

<style type="text/css">

body {
    background: #000000;
    }
#header {
    height: 29px;
    overflow: hidden;
    }
#content {
    background: #ffffff;
    min-height: 200px;
    padding: 10px;
    border-top-right-radius: 10px;
    border-top-right-radius: 10px;
    }

#on {
    background: #ffffff;
    display: inline-block;
    padding: 5px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    vertical-align: top;
    }

#off {
    background: #888888;
    display: inline-block;
    padding: 5px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    vertical-align: top;
    margin-left: -40px;
    }

#seperatoron {
    border: none;
    border-left: 25px solid white;
    border-bottom: 0px;
    height: 0px;
    width: 0px;
    display: inline-block;
    position: relative;
    margin-top: 10px;
    border-right: 25px solid transparent;
    border-top: 25px solid transparent;
    margin-top: 4px;
    margin-left: -2px;
    }

#seperatoroff {
    border: none;
    border-left: 25px solid #888888;
    border-bottom: 0px;
    height: 0px;
    width: 0px;
    display: inline-block;
    position: relative;
    margin-top: 10px;
    border-right: 25px solid transparent;
    border-top: 25px solid transparent;
    margin-top: 4px;
    margin-left: -2px;
    }

</style>


<body>

<div id="header">
<div id="on">Tab 1</div><div id="seperatoron"></div>
<div id="off">Tab 2</div><div id="seperatoroff"></div>
</div>

<div id="content">

Document content section.

</div>

</body>
</html>
Aixenprovence answered 17/1, 2012 at 14:26 Comment(0)
S
1

The rounded border in the upper-left corner is possible with the border-radius property (not in old IE versions). However, the right side of each tab should be done with an image, svg or a rotated div with a css3 transform, but that will give you a headache for sure.

If I were you, I would go for a border radius for topleft and a background-image aligned to the right:

border-top-left-radius: 10px;
background: white url(tab.gif) right top no-repeat;

I think you should also give the second tab a negative margin-left.

Striker answered 17/1, 2012 at 13:51 Comment(0)
P
0

Here is the window typed tab buttons with css

.tablist{
    padding:0;
    margin:0;
    list-style:none;
    display:flex;
    justify-content:center;
}
.tablist>li{
}
.tablist >li>a{
    position: relative;
    display: block;
    color: red;
    text-decoration: none;
    line-height: 1.4;
    border-top: 1px solid red;
    border-radius: 6px 6px 0 0;
    padding: 3px 10px;
    margin: 0 5px;
}
.tablist >li>a:before{
    position: absolute;
    content: "";
    width: 9px;
    height: 29px;
    background: white;
    transform: rotate(21deg);
    border-left: 1px solid red;
    left: -5px;
    top: 2px;
    z-index: -1;
    border-radius: 2px 0 0 0px;

}
.tablist >li>a:after{
    position: absolute;
    content: "";
    width: 9px;
    height: 29px;
    background: white;
    transform: rotate(-21deg);
    border-right: 1px solid red;
    right: -5px;
    top: 2px;
    z-index: -1;
    border-radius: 2px 0 0 0px;

}

And the html will be like this

<ul class="tablist">
<li><a href="jasscript:void(0)">Home</a></li>
<li><a href="jasscript:void(0)">About</a></li>
<li><a href="jasscript:void(0)">Contact us</a></li>
<li><a href="jasscript:void(0)">Blog</a></li>
<li><a href="jasscript:void(0)">Home</a></li>
</ul>
Protohuman answered 28/5, 2016 at 19:56 Comment(0)
P
0

Here's an example using pseudo-elements and flexbox:

enter image description here

.slant_tabs {
  display:flex;
}
.slant_tab {
      border-radius: 0px 0px 0px 0px;
      position: relative;
      line-height:1rem;
      background-color: #FFF;
      background:#DDD;
      border: 2px solid blue;
      border-bottom: none;
      border-right:none;
      margin-right:8px;
  }
  .slant_tab:after {
      display: block;
      content:" ";
      position: absolute;
      transform:skewX(45deg);
      -ms-transform:skewX(45deg);
      -webkit-transform:skewX(45deg);
      z-index: -1;
      background-color: #FFF;
      background:#DDD;
      height: 24px;
      top: -2px;
      border: 2px solid blue;
      border-bottom: none;
      border-left: none;
      width: 28px;
      right: -13px;
  }

  .slant_tab:hover {
    background:blue;
    color:white;
    z-index:10;
  }
  .slant_tab:hover::after {
    background:blue;
  }
  /* .slant_tab_inner element provides the full hoverable area for eachtab, including over slant area, because the slant part itself will not respond to hover. */
  .slant_tab_inner {
    border:none;
    padding: 4px 20px 4px 8px;
    margin-right:-20px;
    cursor:pointer;
  }
<div class="slant_tabs">
   <div class="slant_tab"><div class="arrow"></div><div class="slant_tab_inner">Tab A</div></div>
  <div class="slant_tab"><div class="arrow"></div><div class="slant_tab_inner">Tab B</div></div>
  <div class="slant_tab"><div class="arrow"></div><div class="slant_tab_inner">Tab C</div></div>
 </div>

DEMO: https://jsfiddle.net/p5tcons0/

(Modified from original answer here)

Perineuritis answered 29/10, 2022 at 3:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.