如何使用CSS创建圆角?
解决方案
自从CSS3引入以来,使用CSS添加圆角的最佳方法是使用border-radius属性。
针对Safari, Chrome, Firefox有不同写法,如下所示
-moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px;
像任何其他CSS速记一样,以上内容也可以以扩展格式编写,从而为topleft,topright等实现不同的Border Radius。
-moz-border-radius-topleft: 10px; -moz-border-radius-topright: 7px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 3px; -webkit-border-top-right-radius: 10px; -webkit-border-top-left-radius: 7px; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 3px;
示例:使用CSS 定义4个圆角
<div class="Rounded"> <!-- content --> <div class="RoundedCorner RoundedCorner-TopLeft"></div> <div class="RoundedCorner RoundedCorner-TopRight"></div> <div class="RoundedCorner RoundedCorner-BottomRight"></div> <div class="RoundedCorner RoundedCorner-BottomLeft"></div> </div>
/
* Rounded styling
/
.Rounded {
position: relative;
}
.Rounded .RoundedCorner {
position: absolute;
background-image: url('SpriteSheet.png');
background-repeat: no-repeat;
overflow: hidden;
/* Size of the rounded corner images */
height: 5px;
width: 5px;
}
.Rounded .RoundedCorner-TopLeft {
top: 0;
left: 0;
/* No background position change (or maybe depending on your sprite sheet) */
}
.Rounded .RoundedCorner-TopRight {
top: 0;
right: 0;
/* Move the sprite sheet to show the appropriate image */
background-position: -5px 0;
}
/* Hack for IE6 */
* html .Rounded .RoundedCorner-TopRight {
right: -1px;
}
.Rounded .RoundedCorner-BottomLeft {
bottom: 0;
left: 0;
/* Move the sprite sheet to show the appropriate image */
background-position: 0 -5px;
}
/* Hack for IE6 */
* html .Rounded .RoundedCorner-BottomLeft {
bottom: -20px;
}
.Rounded .RoundedCorner-BottomRight {
bottom: 0;
right: 0;
/* Move the sprite sheet to show the appropriate image */
background-position: -5px -5px;
}
/* Hack for IE6 */
* html .Rounded .RoundedCorner-BottomRight {
bottom: -20px;
right: -1px;
}
日期:2020-03-25 13:30:54 来源:oir作者:oir
