温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css3如何实现圆角边框

发布时间:2026-09-18 22:00:02 来源:亿速云 阅读:96 作者:小樊 栏目:编程语言

在 CSS3 中,实现圆角边框主要使用 border-radius 属性。下面从基础到进阶给你说明。


一、基本用法

1. 统一圆角

.box {
  width: 200px;
  height: 100px;
  border: 2px solid #333;
  border-radius: 10px;
}

表示四个角的圆角半径都是 10px。


2. 分别设置四个角

顺序:左上 → 右上 → 右下 → 左下

.box {
  border-radius: 10px 20px 30px 40px;
}

3. 水平和垂直半径(椭圆角)

.box {
  border-radius: 20px / 10px;
}

表示水平半径 20px,垂直半径 10px。


二、单独设置某个角

.box {
  border-top-left-radius: 10px;
  border-top-right-radius: 20px;
  border-bottom-right-radius: 30px;
  border-bottom-left-radius: 40px;
}

三、常见效果示例

1. 圆形(宽高相等)

.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}

2. 胶囊形(按钮)

.pill {
  height: 40px;
  padding: 0 20px;
  border-radius: 20px;
}

3. 半圆形

.semi {
  width: 100px;
  height: 50px;
  border-radius: 50px 50px 0 0;
}

四、注意事项

  • border-radius 对 块级元素和行内块元素 都生效
  • 不会影响内容布局,只影响视觉边角
  • 兼容性好(IE9+ 支持)

如果你有具体场景(如卡片、头像、对话框),我可以给你更贴合的示例。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手