I need to make like this. Is it possible with pure 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.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With