Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse border radius with css3 [duplicate]

Tags:

css

Since 3 hours I'm trying to find how to inverse border radius, I saw a small code in css3 specially for that, but I can't find it ...

You must know I'm working with wordpress (unfortunately)

Have an idea ?

like image 266
Emilien Avatar asked Sep 25 '16 14:09

Emilien


People also ask

How do you reverse border radius in CSS?

The trick to making the inverted border radius (at least using this method) is to create a pseudo element, and then cut a normal border radius out of that element. Let's set up the pseudo element, and let's at the same time already add the border radius to it to speed life up a little bit!

Can CSS borders be negative?

It is possible to give margins a negative value. This allows you to draw the element closer to its top or left neighbour, or draw its right and bottom neighbour closer to it.

Can you created rounded corners using CSS3?

To create a rounded corner, we use the CSS border-radius property. This property is used to set the border-radius of element.


1 Answers

If your tab has a solid background color you can use pseudo elements to archive this.


First we create a tab with border radius in the top left and top right corners.

.tab {
    -webkit-border-top-left-radius: 10px;
    -webkit-border-top-right-radius: 10px;
    -moz-border-radius-topleft: 10px;
    -moz-border-radius-topright: 10px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

Then we add position: relative, because we need to use position: absolute in the pseudo elements.

.tab {
    position: relative;
}

Now, we are going to create and position our pseudo elements as a quarter of a circle, transparent, with box-shadow to simulate borders.

.tab:before,
.tab:after {
    content: "";
    position: absolute;

    height: 10px;
    width: 20px;

    bottom: 0;
}

.tab:after {
    right: -20px;

    border-radius: 0 0 0 10px;
    -moz-border-radius: 0 0 0 10px;
    -webkit-border-radius: 0 0 0 10px;

    -webkit-box-shadow: -10px 0 0 0 #fff;
    box-shadow: -10px 0 0 0 #fff;
}

.tab:before {
    left: -20px;

    border-radius: 0 0 10px 0;
    -moz-border-radius: 0 0 10px 0;
    -webkit-border-radius: 0 0 10px 0;

    -webkit-box-shadow: 10px 0 0 0 #fff;
    box-shadow: 10px 0 0 0 #fff;
}

And this is the result:

enter image description here

DEMO: jsFiddle

body {
	background: #1c1c1c;
	padding: 50px;
}

.tab {
	float: left;

	width: 90px;
	padding: 10px 15px;
	height: 30px;

	position: relative;

	background: #fff;

	-webkit-border-top-left-radius: 10px;
	-webkit-border-top-right-radius: 10px;
	-moz-border-radius-topleft: 10px;
	-moz-border-radius-topright: 10px;
	border-top-left-radius: 10px;
	border-top-right-radius: 10px;
}

.tab:before,
.tab:after {
	content: "";
	position: absolute;

	height: 10px;
	width: 20px;

	bottom: 0;
}

.tab:after {
	right: -20px;

	border-radius: 0 0 0 10px;
	-moz-border-radius: 0 0 0 10px;
	-webkit-border-radius: 0 0 0 10px;

	-webkit-box-shadow: -10px 0 0 0 #fff;
	box-shadow: -10px 0 0 0 #fff;
}

.tab:before {
	left: -20px;

	border-radius: 0 0 10px 0;
	-moz-border-radius: 0 0 10px 0;
	-webkit-border-radius: 0 0 10px 0;

	-webkit-box-shadow: 10px 0 0 0 #fff;
	box-shadow: 10px 0 0 0 #fff;
}
<div class="tab"></div>
like image 199
agustin Avatar answered Oct 23 '22 21:10

agustin