CSS中设置元素的圆角矩形
2024-09-27 16:08:46
圆角矩形介绍
- 在
CSS
中通过border-radius
属性可以实现元素的圆角矩形。 border-radius
属性值一共有4
个,左上、右上、右下、左下。border-radius
属性值规则如下:第一个值为左上、第二个值为右上、第三个值为右下、第四个值为左下。- 假如
border-radius
属性值都是一致的我可以设置一个属性值即可。
圆角矩形实践
- 圆角矩形基本使用方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 100px;
height: 100px;
border: 2px solid rebeccapurple;
border-radius: 10px 20px 30px 40px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 如果我们的
border-radius
属性值一致实践。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 100px;
height: 100px;
border: 2px solid rebeccapurple;
border-radius: 20px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 如果使用
border-radius
属性值将元素设置为圆形呢。 - 第一步:要设置的元素宽高度必须一致。
- 第二步:使用
border-radius
属性值必须是要设置的元素宽高度的一半。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 100px;
height: 100px;
border: 2px solid rebeccapurple;
border-radius: 50px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 设置椭圆形实践
- 实现椭圆形
border-radius
属性值必须是元素的高度一半即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 100px;
height: 50px;
border: 2px solid rebeccapurple;
border-radius: 25px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
设置半圆形
- 设置右半圆形
border-radius
属性值左上、和左下为元素的宽度一致即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 50px;
height: 100px;
border: 2px solid rebeccapurple;
border-radius: 50px 0px 0px 50px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 设置左半圆形
border-radius
属性值右上、和右下为元素的宽度一致即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 50px;
height: 100px;
border: 2px solid rebeccapurple;
border-radius: 0px 50px 50px 0px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 设置上半圆形
border-radius
属性值左上、和右上为元素的高度一致即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 100px;
height: 50px;
border: 2px solid rebeccapurple;
border-radius: 50px 50px 0px 0px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- 设置下半圆形
border-radius
属性值左下、和右下为元素的高度一致即可。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>圆角矩形</title>
<style>
div{
width: 100px;
height: 50px;
border: 2px solid rebeccapurple;
border-radius: 0px 0px 50px 50px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
最新文章
- XIB 上的控件不显示怎么办
- 【转】sql server 获取每一个类别中值最大的一条数据
- C#制作验证码
- ACM Haffman编码
- Linux下screen命令
- 快速、直接的XSS漏洞检测爬虫 – XSScrapy
- 【转】经典SQL语句大全
- jQuery扩展与noConflict的用法-小示例
- 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件
- MyEclipse 2015利用Cygwin+CDT搭建C/C++开发环境
- Konva入门教程
- 解决No converter found for return value of type: class java.util.ArrayList
- kali网络配置
- SpringBoot之AOP
- 20165313 《网络对抗技术》 Kali安装
- 一道题引出对LinkedList源码的研究
- 查询表DML和DDL操作的最后时间
- android studio git 将项目分享到github,推送到其他平台 码云 等。
- The type android.support.v4.view.ScrollingView cannot be resolved. It is indirectly referenced from
- dedecms 后台修改系统设置,但是config.cache.inc.php文件不能写入