Rounded Corners on DIVs with Background Color

ぃ、小莉子 提交于 2019-11-27 15:56:38

问题


I've got some code that looks like this:

<div id="shell">
    <div id="title">TITLE HERE</div>
    <div id="content">Article Content Goes Here</div>
</div>

The shell div has a grey border that I want rounded corners on. The problem I'm running into is the title div has a green background and it's overlapping the rounded corners of the shell. It either overlaps or doesn't jut up against the edges to provide a fluid look.

I'm looking for a solution that's backwards compatible with IE 7 and 8, but if there's a solution in HTML5 that's simple I would be willing to lose those browsers.

Thanks!


回答1:


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;
}



回答2:


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/




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/6484820/rounded-corners-on-divs-with-background-color

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