当前位置: 首页 > java >正文

CSS3 基础(边框效果)

一、边框效果

属性功能示例值说明
border-radius创建圆角border-radius: 20px;设置元素的圆角半径,支持像素(px)或百分比(%)。值为 50% 时可变为圆形。
box-shadow添加阴影box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);为元素添加外部或内部阴影,支持颜色、模糊半径等。

1、border-radius语法:

border-radius: [水平半径] [垂直半径]

  按左上→右上→右下→左下顺时针排列,省略时对角复制

(如 border-radius: 10px 20px; 表示左上/右下为 10px,右上/左下为 20px

  使用 border-radius 制作特殊图形

<!DOCTYPE html>
<html lang="zh-cn">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>使用 border-radius 制作特殊图形</title><style>body {font-family: Arial, sans-serif;text-align: center;margin: 20px;}.container {display: flex;justify-content: center;flex-wrap: wrap;gap: 20px;}.shape {background-color: #25c447;display: flex;justify-content: center;align-items: center;color: #fff;font-size: 14px;font-weight: bold;}/* 圆形 *//* 元素的宽度和高度必须相同,圆角的半径为元素宽度的一半,或者直接设置圆角半径值为50% */.circle {width: 100px;height: 100px;border-radius: 50%;}/* 椭圆 *//* 元素的宽度和高度不相同,圆角的半径为元素宽度的一半,或者直接设置圆角半径值为50% */.ellipse {width: 150px;height: 100px;border-radius: 50%;}/* 半圆: *//* 制作左半圆或右半圆时,元素的高度是宽度的2倍,而且圆角半径为元素的宽度值 */.half-circle {width: 50px;height: 100px;border-radius: 0 50px 50px 0 ;}/* 半圆: *//* 制作上半圆或下半圆时,元素的宽度是高度的2倍,而且圆角半径为元素的高度值*/.half-circle2 {width: 100px;height: 50px;border-radius: 50px 50px 0 0;}/* 水滴形 */.water-drop {width: 50px;height: 100px;border-radius: 50% 50% 50% 50% / 70% 70% 20% 20%;}/* 扇形 *//* "三同"是元素宽度、高度、圆角半径相同,一不同"是圆角取值位置不同 */.fan {width: 100px;height: 100px;border-radius: 100px 0 0 0;}/* 矩形 */.li {width: 100px;height: 100px;border-radius:0%;         /*矩形有无角*/}</style>
</head>
<body><h1>使用 border-radius 制作特殊图形</h1><div class="container"><div class="shape circle">圆形</div><div class="shape ellipse">椭圆</div><div class="shape half-circle">右半圆</div><div class="shape half-circle2">上半圆</div><div class="shape water-drop">水滴</div><div class="shape fan">扇形</div><div class="shape li">矩形</div></div>
</body>
</html>

 2、box-shadow 盒子阴影

box-shadow: [水平偏移量] [垂直偏移量] [模糊半径] [扩展半径] [颜色] [inset];

  • 水平偏移量‌:阴影水平方向的距离(正值为右,负值为左)。
  • 垂直偏移量‌:阴影垂直方向的距离(正值为下,负值为上)。
  • 模糊半径‌:阴影的模糊程度(值越大越模糊,0 为无模糊)。
  • 扩展半径‌:阴影的扩展范围(正值扩大,负值缩小)。
  • 颜色‌:阴影颜色(支持 HEX、RGB、RGBA 等格式)。
  • inset‌:可选关键字,表示阴影在元素内部(默认是外部)。

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Box-Shadow </title><style>body {font-family: Arial, sans-serif;background-color: #ebecd5;margin: 0;padding: 20px;display: flex;justify-content: space-around;align-items: center;height: 100vh;flex-wrap: wrap;}/* 外阴影 */.box-outer-shadow {width: 300px;height: 200px;background-color: #fff;border-radius: 10px;box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4); /* 增加偏移量和透明度 */display: flex;justify-content: center;align-items: center;text-align: center;}/* 内阴影 */.box-inner-shadow {width: 300px;height: 200px;background-color: #fff;border-radius: 10px;box-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.3); /* 增加模糊半径和透明度 */display: flex;justify-content: center;align-items: center;text-align: center;}/* 多层阴影 */.box-multi-shadow {width: 300px;height: 200px;background-color: #fff;border-radius: 10px;box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4), 0 16px 32px rgba(0, 0, 0, 0.2); /* 增加层次感 */display: flex;justify-content: center;align-items: center;text-align: center;}/* 扩展阴影 */.box-extended-shadow {width: 300px;height: 200px;background-color: #fff;border-radius: 10px;box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4); /* 增加偏移量和模糊半径 */display: flex;justify-content: center;align-items: center;text-align: center;}.box p {font-size: 18px;color: #333;}</style>
</head>
<body><div class="box-outer-shadow"><p>外阴影</p></div><div class="box-inner-shadow"><p>内阴影</p></div><div class="box-multi-shadow"><p>多层阴影</p></div><div class="box-extended-shadow"><p>扩展阴影</p></div>
</body>
</html>

外阴影
  • 向下方偏移 8px,模糊半径 16px,颜色为半透明黑色。
内阴影(inset)
  • 在元素内部添加模糊阴影,常用于按钮按下效果。
多层阴影
  • 叠加两层阴影,实现更立体的层次感。

 扩展阴影

  • 阴影不模糊,扩展 5px,常用于高亮边框效果。

http://www.xdnf.cn/news/1378.html

相关文章:

  • 从 Vue 到 React:React.memo + useCallback 组合技
  • PCB规则
  • 【android bluetooth 协议分析 11】【AVDTP详解 2】【avdtp 初始化阶段主要回调关系梳理】
  • 基于FPGA 和DSP 的高性能6U VPX 采集处理板
  • 深入解析C++ STL Queue:先进先出的数据结构
  • Android Gradle Plugin (AGP) 和 Gradle 的關係
  • 【Qwen2.5-VL 踩坑记录】本地 + 海外账号和国内账号的 API 调用区别(阿里云百炼平台)
  • 学习记录:DAY16
  • 2.RabbitMQ - 入门
  • 从入门到精通:CMakeLists.txt 完全指南
  • AI语音助手自定义角色百度大模型 【全新AI开发套件掌上AI+4w字教程+零基础上手】
  • 永磁同步电机控制算法-反馈线性化控制
  • 官方不存在tomcat10-maven-plugin插件
  • 【模板匹配】图像处理(OpenCV)-part10
  • 【金仓数据库征文】从Oracle到KingbaseES的语法兼容与迁移
  • 常用第三方库精讲:cached_network_image图片加载优化
  • Chrome/Edge浏览器使用多屏完美解决方案,http部署使用https部署的功能
  • 互联网金融岗位简历模板
  • 3.第三章:数据治理的战略价值
  • 【人工智能】Ollama 负载均衡革命:多用户大模型服务的高效调度与优化
  • Vue3父子组件数据同步方法
  • gbase8s存储学习一 rootdbs存储结构以及寻址分析
  • 08-IDEA企业开发工具-集成AI插件通义灵码
  • Java—— 正则表达式 练习
  • 代理模式:控制对象访问的中间层设计
  • C#学习1_认识项目/程序结构
  • 【无标题】spark安装部署
  • TCP 协议:原理、机制与应用
  • cursor改Goland操作习惯
  • 密码学(1)LWE,RLWE,MLWE的区别和联系