Using border-radius and box-shadow together (CSS)

WebkitCssMozilla

Webkit Problem Overview


Ok, I know neither of these properties are completely supported yet, but I'm using them anyway :P

When I add a border-radius and box-shadow (with and without vendor prefixes), the radius of the border-radius is not transparent to the box-shadow. Example: http://cndg.us/3f41a0

Is this possible to fix? I've also noticed that -webkit-box-shadow has some issues with hidden divs.

Webkit Solutions


Solution 1 - Webkit

it is possible check here: http://jsfiddle.net/Zw4QA/1/

i think you have a element inside your div with the rounded corders. You have to apply the corners to this element to. At the moment rounded corners on the parent element will not apply to the children unless you specify it in your CSS.

for more CSS3 magic check this link: http://css3please.com/

Be aware that every single browser has his own way of handling Shadows and border radius http://thany.nl/apps/boxshadows/

Solution 2 - Webkit

According to the documentation at MDN, a box-shadow automatically picks the border-radius of the element itself. Here is a link: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow#:~:text=The%20box%2Dshadow%20property%20enables,on%20the%20same%20rounded%20corners

Solution 3 - Webkit

For table with cells:

JSFiddle

HTML

<table>
    <tr>
        <td class='one'>One</td>
        <td class='two'>Two</td>
    </tr>
    <tr>
        <td colspan="2" class='three'>Three</td>
    </tr>
</table>

CSS

body {
 font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
 padding: 100px;
 background: pink;
}

table {
/* basic */
 background-color: #fff;
 margin: 0 auto;
 width: 200px;
 padding: 100px;
 text-align: center;
/* border-radius */
 border-radius: 20px;
/* box-shadow */
 box-shadow: rgba(0,0,0,0.8) 0 0 10px;
 border-collapse: collapse;
}

table td{
  color: white;
}

td.one{
    border-radius: 20px 0 0 0;
    background-color: black;
}
td.two{
    border-radius: 0 20px 0 0;
    background-color: darkgreen;
}
td.three{
    border-radius: 0 0 20px 20px;
    background-color: darkred;
}

Solution 4 - Webkit

While dinking around on my father's website I discovered that you can add the radius characteristic to shadow. So I have a calendar inside a div, both have rounded edges (0.7em to be exact) and I wanted to add a drop shadow to it, but those almost always have a square edge and as such would clash with my rounded edges. Just messing around with box-shadow attribute and decide what if I add radius to it? So I did. Can't find anywhere online that mentions this technique so I might have discovered something unique. Anyways enough back story here's the codes:

CSS:

box-shadow-bottom-right-radius: 0.7em; //you can enter whatever value you want
box-shadow-bottom-left-radius: 0.7em;
box-shadow-top-right-radius: 0.7em;
box-shadow-top-left-radius: 0.7em;

There you go so you're adding a radius to the box shadow itself like you would normally do to a border.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGaryView Question on Stackoverflow
Solution 1 - WebkitmeoView Answer on Stackoverflow
Solution 2 - WebkitDaggie Blanqx - Douglas MwangiView Answer on Stackoverflow
Solution 3 - WebkitdylfinView Answer on Stackoverflow
Solution 4 - WebkitRCCRFView Answer on Stackoverflow