Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make angled tab like this using css?

Tags:

css

css-shapes

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

enter image description here

like image 330
Jitendra Vyas Avatar asked Jan 17 '12 13:01

Jitendra Vyas


People also ask

How do you make an arc shape in CSS?

CSS Shapes It's possible to draw circles and arcs in CSS by simply creating a square <div> and setting border-radius to 50%. Each side of the border can take a different color or can be set to transparent . The background-color property sets the shape's fill, if any.


2 Answers

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>
like image 167
The Pragmatick Avatar answered Oct 29 '22 21:10

The Pragmatick


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.

like image 34
Eirinn Avatar answered Oct 29 '22 22:10

Eirinn