Rounded Corners on DIVs with Background Color

*爱你&永不变心* 提交于 2019-11-29 01:15:52

In your markup, you have to give border-radius to both #shell and #title so that the #title's sharp corners don't overlap #shell's.

A live example, http://jsfiddle.net/BXSJe/4/

#shell {
 width: 500px;
 height: 300px;
 background: lightGrey;
 border-radius: 6px;
}

#title {
 background: green;
 padding: 5px;
 border-radius: 6px 6px 0 0;
}

Another way to accomplish this was to set the outer div to have a overflow to hidden

#shell {
 width:500px;
 height:300px;
 background:lightGrey; 
 border-radius: 10px 10px 10px 10px;
 overflow:hidden;
}
#title {
 background:green;
 padding:5px;
}

http://jsfiddle.net/jdaines/NaxuK/

EdoDodo

You'll probably want to round just the top two corners of the title div with the same radius as the shell div so that they don't overlap. The CSS3 you would use is:

border-top-left-radius: XXpx
border-top-right-radius: XXpx

For backward compatibility with old Mozilla browsers you should also use:

-moz-border-radius-topleft: XXpx
-moz-border-radius-topright: XXpx

And for old versions of WebKit browsers (Safari, mainly), you can use:

-webkit-border-top-left-radius: XXpx
-webkit-border-top-right-radius: XXpx

However, there is nothing you can do about old Internet Explorer browsers as far as I know, except use images.

You can use PIE with IE7 and 8. It enables some CSS3 functionality in IE7 and IE8. And yes, I know, it is not a browser, it's a pain. Maybe a curse.

You can check it here.

Michael Schwartz

Internet Explorer did not support border-radius until IE9, much to the frustration of developer and designers. With IE9, the important steps are using the edge META tag and provide the border radius:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<style>
border-top-right-radius: 7px;
border-top-left-radius: 7px;
border-bottom-right-radius: 2px;
border-bottom-left-radius: 2px;
</style>

Source - http://davidwalsh.name/css-rounded-corners

I'd rather use images, but IE can do down the drain. Microsoft should step up it's game, and support CSS3.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!