My UI has an unordered list on the left. When a list item is selected, a div
appears on the right of it. I'd like to have a curved outer corner where the <li>
and the <div>
meet. Some people call this a negative border radius or an inverted corner. See the white arrow in the image below.
To extend the blue <li>
to the edge of the <ul>
, I'm planning to do something like this:
li {
right-margin: 2em;
border-radius: 8px;
}
li.active {
right-margin: 0;
border-bottom-right-radius: 0;
border-top-right-radius: 0;
}
Is there a better way to extend the <li>
to the edge of the <ul>
? Obviously, I'll include the webkit and mozilla border radius CSS as well.
The main thing I'm unsure about is that outer corner underneath the bottom right corner of the active <li>
. I have some ideas, but they seem like hacks. Any suggestions?
NOTE that the <ul>
is indicated in grey, but it would be white in the real design. Also, I'm planning to use Javascript to position the <div>
correctly when an <li>
is selected.
I came up with a solution that requires less markup. In summary, instead of using margins it uses white rounded borders, then we position the active li behind the white rounded borders to achieve the inverted border-radius effect.
http://jsfiddle.net/zrMW8/
And less CSS too! (this is mind bending):
To tell you the truth I'm not sure it's a better version, it does make gradient/image backgrounds easy (for non active li's, at least) but you can't apply an image/gradient background to the body. It's also "bad magic" en the sense that it works in a non-intuitive way.
This nice Inverse Border Radius in CSS tutorial could do the trick. Explains how to do inverse border radius for tabs. But it could be easily adapted to streamline your css since it uses
:after
instead of creating too many extra elements.To do this over a non-solid bg, I don't think you can do it with CSS, but you could use canvas or SVG to the same effect - not exactly what you asked for, though.
However, there does appear to be a proposal for negative border radius that would solve the problem. Maybe some day, right.
Cleaner Solution (Less Code & Background Gradient Allowed)
See the fiddle (or another), which is using this html:
And this css (the key is to allow the
border-radius
andborder-width
on the pseudo-elements to make the inverted circle for you; I've omitted thegradient
code.):Well, as it turns out, I managed to solve the problem myself. I hacked together a demo -- check it out.
Essentially, several additional DOM elements are required and a fair amount of CSS. And as mentioned in the link provided by @Steve, a solid background is required. I don't believe there is any way to do this over a gradient background or other pattern.
I ended up with HTML like this:
I haven't optimized any of the CSS as I just hacked it together. But perhaps it will help someone else. I've only tested this in Google Chrome on Mac OSX.
Not really, sorry, per
Invert rounded corner in CSS?