13

I was working on the CSS of my website when I had the idea of making tabs (or tab) for my links. I have the text removed in this example, but this is going to be a navigation bar basically. Here's the picture:

enter image description here

My question is, how would I get a 'border-radius'-ish effect where the BLACK arrow is pointing and look like the effect where the BLUE arrow is pointing? Is there a certain webkit command to help me, or should I make it an img or perhaps jquery?

Thanks a ton!(I draw some beautiful arrows, right?)

Kragalon
  • 420
  • 1
  • 6
  • 25

3 Answers3

19

Not using the native border-radius. As mentioned on MDN "Negative values are invalid". You could definitely look for a library out there which does this for you automatically (though I find the approach taken in Philip's suggested library to be particularly outdated).

Using pure CSS I have come up with an approach. The idea is to add 4 extra elements inside your container, set their background to the same color as your page background (so this will not let page content underneath filter through – for that, you’d need SVG masking or similar), and to position them in such a way that they lie just outside of the element itself. We then apply a border-radius which gives the affect:

#main {
    margin: 40px;
    height: 100px;
    background-color: #004C80;
    position: relative;
    overflow: hidden;
}

#main div {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 100%;
    background-color: #FFF;
}

.top { top: -10px; }
.bottom { bottom: -10px; }
.left { left: -10px; }
.right { right: -10px; }
<div id="main">
    <div class="top left"></div>
    <div class="top right"></div>
    <div class="bottom left"></div>
    <div class="bottom right"></div>
</div>
ecmanaut
  • 5,030
  • 2
  • 44
  • 66
Ian Clark
  • 9,237
  • 4
  • 32
  • 49
  • Thanks for the help everyone. I ended up making 2
    on either side of the tab and then gave the parent div a border which matched my headers background as well as giving the child div an orange background. I then gave the parent a border-radius on the bottom-right and bottom-left border, respectively. It looks great, but I see that this answer was somewhat related. So, thank you.
    – Kragalon Mar 15 '14 at 21:50
  • 4
    @IanClark sure. The corner is fake. Any content behind it will be hidden since the background color is solid. It's not a cutout. – Streching my competence Oct 18 '18 at 20:52
  • 1
    The best solution is to make the design of the website/app fixed size at that point, and make an .SVG that can actually have a true cutout. Perhaps it'd work well with dynamic size too with right measurements. – Streching my competence Oct 18 '18 at 20:54
  • Ive been looking around for a solution for a real cutout corner that is not SVG, ive always kept this at the ack of my head when suddenly ive made this accidentally.. dropping this here for any1 else that stumbles across the same issue - [link](https://codesandbox.io/s/keen-framework-lgw0b?file=/src/styles.css) – kw7 Jul 02 '21 at 17:08
5

if your element has only a background color, you may use pseudo-elements and box-shadow.

a hudge box-shadow on pseudo elements can fill the element. examples : http://codepen.io/gcyrillus/pen/hlAxo , http://codepen.io/gc-nomade/pen/dtnIv , http://codepen.io/gcyrillus/pen/yJfjl .

adding a linear gradient, you may draw a box similar to what you look for that can grow any heights : http://codepen.io/anon/pen/cIxwD .

 div {
   width:800px;
   margin:auto;
   position:relative;
   overflow:hidden;
   min-height:2000px;
    background:linear-gradient(to bottom,
    rgba(255,255,255,0) 0,
    rgba(255,255,255,0) 100px,
    orange 100px,
    orange
    );
 }
div:before,
div:after
{
  content:'';
  position:absolute;
  top:0;
  height:30px;
  width:60px;
  box-shadow: 0 0 0 500px orange;
  border-radius:0 0 0.5em 0;

}
div:after {
  right:0;
  border-radius: 0 0 0 0.5em;
}
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
1

You can use this plugin. http://jquery.malsup.com/corner/ (uses jquery)

And then do the following:

 $(this).corner("bite");

Requires jQuery and jQuery Corner!

Philip G
  • 4,098
  • 2
  • 22
  • 41