不要图片?CSS实现大屏常见不规则边框(系列二)

news/2024/7/5 4:59:09

前言

👏不要图片?CSS实现大屏常见不规则边框(系列二),速速来Get吧~
🥇文末分享源代码。记得点赞+关注+收藏!

1.实现效果

在这里插入图片描述

2.实现原理

系列一已经陈述了相关原理,感兴趣的小伙伴直接参考不要图片?CSS实现大屏常见不规则边框(系列一)

3.实现步骤

  • 定义css变量,–w宽度,–h高度,–line-bg渐变边框色,–content-bg内容背景色 , --pathclip-path裁剪形状
:root {
/* 渐变边框色 */
 --line-bg: linear-gradient(
   180deg,
   rgba(138, 203, 255, 1),
   rgba(41, 106, 143, 1),
   rgba(190, 40, 40, 1)
 );
 /* 定义宽高 */
 --w: 300px;
 --h: 350px;
 /* 内容背景色 */
 --content-bg: linear-gradient(181deg, #021734 0%, #3d1328 100%);
 /* clip-path裁剪 */
 --path: polygon(
   0 0,
   calc(100% - 10px) 0,
   100% 10px,
   100% 100%,
   10px 100%,
   0 calc(100% - 10px)
 );
}
  • 绘制父元素,设置相对定位
 <div class="dialog"></div>
.dialog {
	position: relative;
	font-size: 20px;
	text-shadow: 0 10px 12px #001025;
}
  • 添加子元素,设置宽高为w和h,父元素随着子元素大小拉伸,设置resize进行拉伸,并设置最小宽度最大宽度

在这里插入图片描述

<div class="dialog">
	+<div class="box flex-row j_c">CSS 实现不规则边框(2</div>
</div>

.box {
	width: var(--w);
	height: var(--h);
	background: var(--line-bg);
	border-radius: 6px;
	position: relative;
	z-index: 1;
	/* 添加resize */
	overflow: hidden;
	resize: both;
	min-width: 250px;
	min-height: 100px;
}
  • 给box设置伪元素,设置内容背景色,设置z-index为-1,不遮挡内容文字

在这里插入图片描述

.box::after {
 content: "";
 width: calc(100% - 4px);
 height: calc(100% - 4px);
 position: absolute;
 /* 定义背景色 */
 background: var(--content-bg);
 /* 水平垂直 居中 */
 left: 50%;
 top: 50%;
 transform: translate(-50%, -50%);
 z-index: -1;
 /* 添加圆角 */
 border-radius: 4px;
}
  • 给父元素设置伪元素,设置相应的border,绝对定位在子元素的左上角

在这里插入图片描述

.dialog::after {
	content: "";
	border: 3px solid #32c5ff;
	width: 40%;
	height: 70%;
	position: absolute;
	left: -1px;
	top: -1px;
	z-index: 1;
	border-right: none;
	border-bottom: none;
	border-radius: 6px 0 0 0;
}
  • 在父元素内添加新标签,宽为父元素的80%,高度为90%,clip-path裁剪实现右下角的不规则形状,设置绝对定位,right为-8px,bottom为-8px

在这里插入图片描述

<div class="dialog">
	+<span class="dialog-rect"></span>
	<div class="box flex-row j_c">CSS 实现不规则边框(2</div>
</div>
.dialog-rect {
	width: 80%;
	height: 90%;
	position: absolute;
	right: -8px;
	bottom: -8px;
	border-radius: 6px;
	background: #66b5f3;
	clip-path: var(--path);
}
  • 为dialog-rect添加伪元素,设置内容背景色,并clip-path进行与其父元素一致的裁剪

在这里插入图片描述

.dialog-rect::after {
	content: "";
	position: absolute;
	width: calc(100% - 3px);
	height: calc(100% - 3px);
	/* 水平垂直 居中 */
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	z-index: -1;
	background: #093258;
	border-radius: 4px;
	clip-path: var(--path);
}
  • 将box进行resize缩放,就实现好啦

在这里插入图片描述

4.实现代码

<style>
  :root {
    /* 渐变边框色 */
    --line-bg: linear-gradient(
      180deg,
      rgba(138, 203, 255, 1),
      rgba(41, 106, 143, 1),
      rgba(190, 40, 40, 1)
    );
    /* 定义宽高 */
    --w: 300px;
    --h: 350px;
    /* 内容背景色 */
    --content-bg: linear-gradient(181deg, #021734 0%, #3d1328 100%);
    /* clip-path裁剪 */
    --path: polygon(
      0 0,
      calc(100% - 10px) 0,
      100% 10px,
      100% 100%,
      10px 100%,
      0 calc(100% - 10px)
    );
  }
  body {
    background: linear-gradient(
      270deg,
      rgba(1, 33, 62, 0.95) 0%,
      rgba(1, 33, 62, 0.9) 87%
    );
  }
  .dialog {
    position: relative;
    font-size: 20px;
    text-shadow: 0 10px 12px #001025;
  }
  .box {
    width: var(--w);
    height: var(--h);
    background: var(--line-bg);
    border-radius: 6px;
    position: relative;
    z-index: 1;
    /* 添加resize */
    overflow: hidden;
    resize: both;
    min-width: 250px;
    min-height: 100px;
  }
  .box::after {
    content: "";
    width: calc(100% - 4px);
    height: calc(100% - 4px);
    position: absolute;
    /* 定义背景色 */
    background: var(--content-bg);
    /* 水平垂直 居中 */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: -1;
    /* 添加圆角 */
    border-radius: 4px;
  }
  .dialog-rect {
    width: 80%;
    height: 90%;
    position: absolute;
    right: -8px;
    bottom: -8px;
    border-radius: 6px;
    background: #66b5f3;
    clip-path: var(--path);
  }
  .dialog-rect::after {
    content: "";
    position: absolute;
    width: calc(100% - 3px);
    height: calc(100% - 3px);
    /* 水平垂直 居中 */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: -1;
    background: #093258;
    border-radius: 4px;
    clip-path: var(--path);
  }
  .dialog::after {
    content: "";
    border: 3px solid #32c5ff;
    width: 40%;
    height: 70%;
    position: absolute;
    left: -1px;
    top: -1px;
    z-index: 1;
    border-right: none;
    border-bottom: none;
    border-radius: 6px 0 0 0;
  }
</style>
<body>
  <div class="dialog">
    <span class="dialog-rect"></span>
    <div class="box flex-row j_c">CSS 实现不规则边框(2</div>
  </div>
</body>

5.写在最后🍒

看完本文如果觉得对你有一丢丢帮助,记得点赞+关注+收藏鸭 🍕
更多相关内容,关注🍥苏苏的bug,🍡苏苏的github,🍪苏苏的码云~

http://lihuaxi.xjx100.cn/news/1001952.html

相关文章

NLP | SentenceTransformer将句子进行编码并计算句子语义相似度

环境设置&#xff1a; SentenceTransformertransformers SentenceTransformers Documentation — Sentence-Transformers documentation (sbert.net) Sentence Transformer是一个Python框架&#xff0c;用于句子、文本和图像嵌入Embedding。 这个框架计算超过100种语言的句子…

兆芯最新X86 CPU曝光:性能与英特尔/AMD相比,没落后10年

众所周知&#xff0c;在PC领域&#xff0c;X86完全是处于垄断地全的&#xff0c;至少占了90%以上的份额。其它的像MIPS、ARM、RISC-V等等&#xff0c;都不是X86的对手。 这与X86是复杂指令集有关&#xff0c;更与X86绑定了windows操作系统&#xff0c;有坚固的intel联盟有关&am…

《iTOP-3568开发板快速测试手册》第6章 Ubuntu系统功能测试 (5)

瑞芯微RK3568芯片是一款定位中高端的通用型SOC&#xff0c;采用22nm制程工艺&#xff0c;搭载一颗四核Cortex-A55处理器和Mali G52 2EE 图形处理器。RK3568 支持4K 解码和 1080P 编码&#xff0c;支持SATA/PCIE/USB3.0 外围接口。RK3568内置独立NPU&#xff0c;可用于轻量级人工…

LeetCode:455. 分发饼干——贪心算法

&#x1f34e;道阻且长&#xff0c;行则将至。&#x1f353; &#x1f33b;算法&#xff0c;不如说它是一种思考方式&#x1f340;算法专栏&#xff1a; &#x1f449;&#x1f3fb;123 贪心算法是在每个阶段选取局部最优解&#xff0c;最终得到全局最优解的一种思想。贪心算法…

算法 DAY20 二叉树 || 654.最大二叉树 617.合并二叉树 700.二叉搜索树中的搜索 98.验证二叉搜索树

654.最大二叉树 蛮简单的&#xff0c;逻辑跟构造树基本一致 /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : val(0), left(nullptr), right(nullptr) {}* TreeNode(int x) : …

医学影像系统弱监督语义分割集成的探索

Exploring Weakly Supervised Semantic Segmentation Ensembles for Medical Imaging Systems 摘要 利用复杂数据集的低质量CAM预测来提高结果的准确性使用低阈值CAMs以高确定性覆盖目标对象通过组合多个低阈值cam&#xff0c;在突出显示目标对象的同时均匀地消除它们的错误 …

【通过redis生成编码】生成不重复的序列号

/*** 生成一个序列号&#xff0c;每天从0开始自增* yyyyMMdd0001* Param leftCode编号特定前缀* */public String getSequence(String leftCode){SimpleDateFormat simpleDateFormat new SimpleDateFormat("yyyyMMdd");String dateTime simpleDateFormat.format(ne…

STM32F103引脚输入输出模式详解

目录 一&#xff1a;输入模式 1.1&#xff1a;模拟输入 1.2&#xff1a; 浮空输入 1.3&#xff1a;上拉输入 1.4&#xff1a;下拉输入 1.5&#xff1a; 为什么没有复用输入配置模式 二&#xff1a;输出模式 2.1&#xff1a;推挽输出 2.2&#xff1a;开漏输出 2.3&#xf…