border-radius 圆角边框

本文详细介绍了CSS3中的border-radius属性,包括如何使用该属性创建圆角边框,以及不同浏览器的支持情况。此外,还展示了如何在特定位置应用圆角效果,并提供了示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       在css3.0中,又添加了一个新的属性border-radius,使用border-radius这个属性可以实现圆角边框的效果。除IE和遨游外,目前有Firefox ,Safari,Chrome,Opera支持该属性,其Safari,Chrome,Opera是支持最好的,依照了w3c的标准,仅仅使用border-radius,就可以实现效果,无需加入前缀-webkit。而火狐依然需要加上前缀-moz。
即:
Firefox支持border-radius(圆角):-moz-border-radius:10px;

webkit内核的Safari和Chrome支持border-radius(圆角):-webkit-border-radius:10px;

Opera支持border-radius(圆角):border-radius:10px;

IE不支持border-radius(圆角)

效果图:(IE和遨游不支持!)



代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>圆角效果border-radius</title>
<style type="text/css">
body,div{margin:0;padding:0;}
.border{width:200px;border:10px solid gray;height:20px;
-moz-border-radius:10px;/*仅Firefox支持,实现圆角效果*/
-webkit-border-radius:10px;/*仅Safari,Chrome支持,实现圆角效果*/
-khtml-border-radius:10px;/*仅Safari,Chrome支持,实现圆角效果*/
border-radius:10px;/*仅Opera,Safari,Chrome支持,实现圆角效果*/
}
</style>
</head>
<body>
<div class="border">border radius</div>
</body>
</html>



再此我们还可以随意指定圆角的位置,上左,上右,下左,下右四个方向。
在firefox、webkit内核的Safari,Chrome和 Opera的具体书写格式如下:

上左效果:

-moz-border-radius-topleft / -webkit-border-top-left-radius / border-top-left-radius   上左



上右效果:

-moz-border-radius-topright / -webkit-border-top-right-radius / border-top-right-radius 上右


下左效果:

-moz-border-radius-bottomleft / -webkit-border-bottom-left-radius / border-bottom-left-radius 下左


下右效果:

-moz-border-radius-bottomright / -webkit-border-bottom-right-radius /border-bottom-right-radius  下右




然后我们可以做些效果:
例如常见的 标题栏 仅仅需要在上面用到圆角效果,如图:

代码 :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>圆角效果border-radius</title>
<style type="text/css">
.border{width:120px;border:15px solid gray;height:20px;
background:gray;color:#fff;
-moz-border-radius-topright:15px;
-moz-border-radius-topleft:15px;
-webkit-border-top-right-radius:15px;
-webkit-border-top-left-radius:15px;
border-top-right-radius:15px;
border-top-left-radius:15px;
}
</style>
</head>
<body>
<div class="border">border radius</div>
</body>
</html>


代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>圆角效果border-radius</title>
<style type="text/css">
.border{width:120px;border:15px solid gray;height:20px;
background:gray;color:#fff;
-moz-border-radius-topright:15px;
-moz-border-radius-bottomleft:15px;
-webkit-border-top-right-radius:15px;
-webkit-border-bottom-left-radius:15px;
border-top-right-radius:15px;
border-bottom-left-radius:15px;
}
</style>
</head>
<body>
<div class="border">border radius</div>
</body>
</html>



万变不离其宗,仅仅需要改下的border-radius的方向,就可以实现一些很有用的效果,代码变的越来越简单。

 

### 解决 `border-radius` 底部圆角不生效的方法 当遇到 `border-radius` 的底部圆角无法正常工作的情况时,通常是因为其他样式属性干扰了其表现。为了确保 `border-radius` 能够按照预期作用于元素的四个角落,可以采取以下措施: #### 1. 检查父级容器的影响 如果子元素设置了绝对定位 (`position: absolute`) 或者浮动 (`float`) 属性,则可能会影响 `border-radius` 效果的应用。此时应确认父级容器是否有溢出隐藏设置(`overflow:hidden`)或其他影响布局的方式。 #### 2. 设置明确的高度和宽度 对于某些特定类型的元素来说,如果没有指定高度或宽度可能会导致 `border-radius` 不起效。因此,在定义 `.notepad` 类时已经设定了固定尺寸[^1]: ```css #notepad { background: #f7f7f7; width: 500px; height: 500px; } ``` #### 3. 使用独立的边框半径声明 有时组合式的 `border-radius` 可能会因为浏览器解析顺序而出现问题。尝试分别设定各个方向上的圆角大小来解决问题: ```css .yourElement{ border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; } ``` #### 4. 清除默认内联样式 确保没有来自HTML标签本身的默认样式覆盖自定义CSS规则。可以通过重置样式表清除潜在冲突: ```css *, *::before, *::after { box-sizing: border-box; } body, html { margin: 0; padding: 0; height: 100%; } ``` 上述代码片段有助于统一不同浏览器之间的渲染差异并减少意外情况的发生[^3]。 通过以上方法调整后应该能够有效解决 `border-radius` 在页面中的应用问题。若仍然存在异常现象,建议进一步排查是否存在 JavaScript 动态修改 DOM 结构等情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值