具有边框半径和不同边框颜色的多色进度条

如何解决具有边框半径和不同边框颜色的多色进度条

我正在尝试创建此进度条,但由于它具有边框半径和每个子进度元素不同的边框颜色,所以很难。

任何人都知道如何实现它?

enter image description here

这是我到目前为止所取得的成就,其中不包括边框: Codepen

WITH t(json_extracted,str) AS
(
SELECT JSON_VALUE (JSONDetail,'$.comment'),SUBSTRING(  
                 JSONDetail,PATINDEX('%"comment"%',JSONDetail),PATINDEX('%"contacts"%',JSONDetail)-PATINDEX('%"comment"%',JSONDetail)
                 ) 
  FROM tab
),t2(json_extracted,str) AS
(
SELECT json_extracted,TRIM(
            SUBSTRING( str,PATINDEX('%:%',str) + 1,PATINDEX('%,%',str) - PATINDEX('%:%',str) - 1 ) )
  FROM t
)
SELECT SUBSTRING(str,2,LEN(str)-2) AS extracted_comment,CASE WHEN json_extracted = SUBSTRING(str,LEN(str)-2) 
            THEN
                 'No'
            ELSE
                 'Yes'
            END AS "is_it_corrupted"
  FROM t2
body {
  display: flex;
  justify-content: center;
}

.progress-bar {
  height: 24px;
  width: 280px;
  background: #eaeaea;
  border-radius: 16px;
  display: flex;
  overflow: hidden;
}

.progress-bar-fill-1 {
  width: 30%;
  background: #F16172;
  box-sizing: border-box;
  border-right: 1px solid white;
}

.progress-bar-fill-2 {
  width: 20%;
  background: #31C4F3;
  box-sizing: border-box;
  border-right: 1px solid white;
}

例如,如果我尝试向<div class="progress-bar"> <div class="progress-bar-fill-1"></div> <div class="progress-bar-fill-2"></div> </div>添加边框,则边框不会出现在角落。

enter image description here

请注意,我事先不知道百分比值,因此无法通过在第一个进度元素中添加.progress-bar-fill-1来解决问题。

谢谢

解决方法

body {
  display: flex;
  justify-content: center;
}

.progress-bar {
  height: 24px;
  width: 280px;
  background: #eaeaea;
  border-radius: 16px;
  display: flex;
  overflow: hidden;
}


.progress-bar-fill-1 {
  position: relative;
  width: 30%;
  z-index: 1;
}

.progress-bar-fill-1:before {
  position: absolute;  
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  content: "";
  background: #F16172;
  box-sizing: border-box;
  border-right: 1px solid white;
  border: 1px solid black;
  border-radius: 16px;
}

.progress-bar-fill-2 {
  width: 20%;
  position:relative;  
}

.progress-bar-fill-2:before {
  position: absolute;
  left: -16px;
  right: 0;
  top: 0;
  bottom: 0;
  content: "";
  background: #31C4F3;
  box-sizing: border-box;
  border-right: 1px solid white;
  border-radius: 16px;
}

请检查结果。 您使用了flex。因此我们无法将边距添加到第二个div。

,

具有剪切路径,伪元素和一些CSS变量,您可以轻松地使用一个元素进行此操作。诀窍是让3个元素彼此重叠(主要元素和2个伪元素),然后剪切伪元素以仅显示所需的部分:

.progress-bar {
  --b:2px; /* boder width */
  --s:2px; /* space between progress */

  height: 30px;
  width: 300px;
  margin:5px;
  background: #eaeaea;
  border-radius: 20px;
  position:relative;
  border:var(--b) solid grey;
  position:relative;
}
.progress-bar::before,.progress-bar::after{
  content:"";
  border-radius:inherit;
  border:inherit;
  box-sizing: border-box;
  position:absolute;
  top:calc(-1*var(--b));
  left:calc(-1*var(--b));
  bottom:calc(-1*var(--b));
  right:calc(-1*var(--b));
}

.progress-bar::before {
  background: #F16172;
  border-color:red;
  clip-path:inset(0 calc(100% - var(--f1)) 0 0);
}

.progress-bar::after {
  background: #31C4F3;
  border-color:blue;
  clip-path:inset(0 calc(100% - var(--f1) - var(--f2)) 0 calc(var(--f1) + var(--s)));
}
<div class="progress-bar" style="--f1:30%;--f2:20%;"></div>

<div class="progress-bar" style="--f1:50%;--f2:20%;--b:3px;"></div>

<div class="progress-bar" style="--f1:60%;--f2:10%;--s:5px"></div>

<div class="progress-bar" style="--f1:20%;--f2:70%;--b:1px"></div>

<div class="progress-bar" style="--f1:20%;--f2:80%;--s:10px"></div>

,

为什么会出现此问题:

父元素使用Server: Containers: 6 Running: 3 Paused: 0 Stopped: 3 Images: 185 Server Version: 19.03.12 Storage Driver: overlay Backing Filesystem: extfs Supports d_type: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc nvidia Default Runtime: runc Init Binary: docker-init containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 5.7.2-kd-cluster Operating System: Debian GNU/Linux 9 (stretch) OSType: linux Architecture: x86_64 CPUs: 32 Total Memory: 125.8GiB Name: dpl01 ID: KBGO:2E6L:NIHR:UQAL:K5CN:XWBI:R7TK:WWZF:MZBT:BCHE:HUQW:UKKM Docker Root Dir: /data/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false overflow: hidden;。导致具有圆角的父元素并将其中的所有内容屏蔽到父元素的原因。

由于子元素(又名border-radius: 16px;)最初是正方形,因此边框也将变为正方形。但是子元素的开头/开头将被其父元素掩盖并发生溢出。

为此,解决方案是也将第一个子元素四舍五入到被屏蔽的父元素中,如下所述。

解决方案:

您还必须在第一个子元素上添加边框半径。也称为.progress-bar-fill-1border-radius: 0 0 16px 16px 0;,如下例所示。

固定的代码示例:

.progress-bar-fill-1
body {
  display: flex;
  justify-content: center;
}

.progress-bar {
  height: 24px;
  width: 280px;
  background: #eaeaea;
  border-radius: 16px;
  display: flex;
  overflow: hidden;
}

.progress-bar-fill-1 {
  width: 30%;
  background: #F16172;
  box-sizing: border-box;
  border-right: 1px solid white;
  border-radius: 0 0 16px 16px 0;
}

.progress-bar-fill-2 {
  width: 20%;
  background: #31C4F3;
  box-sizing: border-box;
  border-right: 1px solid white;
}

,

如果我将其添加到.progress-bar-fill-1

border-top-left-radius: 16px;
border-bottom-left-radius: 16px;

例如,在.progress-bar-fill-1很小的情况下,.progress-bar-fill-2的边界也会有同样的问题,因此仍然无法解决问题。.因此,我需要一个更通用的解决方案因为我需要用它来创建一个React组件。

这是问题所在: enter image description here

body {
  display: flex;
  justify-content: center;
}

.progress-bar {
  height: 24px;
  width: 500px;
  background: #eaeaea;
  border-radius: 16px;
  display: flex;
  overflow: hidden;
}

.progress-bar-fill-1 {
  width: 1%;
  background: #F16172;
  box-sizing: border-box;
  border-right: 1px solid white;
  border: 1px solid black;
  border-top-left-radius: 16px;
  border-bottom-left-radius: 16px;
}

.progress-bar-fill-2 {
  width: 20%;
  background: #31C4F3;
  box-sizing: border-box;
  border-right: 1px solid white;
  border: 1px solid blue;
  border-left: none;
}
<div class="progress-bar">
  <div class="progress-bar-fill-1"></div>
  <div class="progress-bar-fill-2"></div>
</div>

,

我已经稍微修改了您的代码。 1%时看起来效果不佳,但2%等等看起来就像设计一样。

body {
  display: flex;
  justify-content: center;
}

.progress-bar {
  height: 24px;
  width: 500px;
  background: #eaeaea;
  border-radius: 16px;
  display: flex;
  overflow: hidden;
}

.progress-bar-fill-1 {
  width: 2%;
  background: #F16172;
  box-sizing: border-box;
  border-right: 1px solid white;
  border-top: 1px solid red;
  border-bottom: 1px solid red;
  border-left: 1px solid red;
  border-top-left-radius: 16px;
  border-bottom-left-radius: 16px;
}

.progress-bar-fill-2 {
  width: 20%;
  background: #31C4F3;
  box-sizing: border-box;
  border-top: 1px solid blue;
  border-bottom: 1px solid blue;
  border-right: 1px solid white;
  border-left: none;
}
<div class="progress-bar">
  <div class="progress-bar-fill-1"></div>
  <div class="progress-bar-fill-2"></div>
</div>

,

我设法找到了一种解决方案,该解决方案还支持IE11(包括IE11),并包含动画幻灯片: https://jsfiddle.net/5kphcLqg/

@keyframes slideInFill {
  0% {
    width: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  } 

  99% {
    border-top-right-radius: 0px;
    border-bottom-right-radius: 0px;
  }

  100% {
        border-top-right-radius: 16px;
    border-bottom-right-radius: 16px;
  }
}

@keyframes slideInBorder {
  from {
    width: 0;
  }
}
 
.container { 
  position: relative;
}

.borders {
  height: 24px;
  width: 280px;
  background: #DCDFDF;
  display: flex;
  border-radius: 16px;
  overflow: hidden;
  position: absolute;
  top: 0;
  box-sizing: border-box;
}

.borders-fill-1 {  
  position: relative;
  width: 20%;
  background: #06A2D4;
}

.animate {
  height: 24px;
  top: 0;   
  animation: slideInBorder 1s ease-in forwards;  
}

.borders-fill-1:after {
  content: '';
  position: absolute;
  height: 100%;
  width: 1px;
  background: white;
  right: 0;
  z-index: 9
}

.borders-fill-2:after {
  content: '';
  position: absolute;
  height: 100%;
  width: 1px;
  background: white; 
  right: 0;
  z-index: 9
}

.borders-fill-2 {
  width: 78%;
  background: #D31A47;  
  position: relative;
}

.fill-bg {
  background: #eaeaea;
  width: 280px;
  height: 24px;
  position: absolute;
  border-radius: 16px;
  background-clip: content-box;
  padding: 1px;
  box-sizing: border-box; 
}

.filling-wrapper {
  border-radius: 16px;
  width: 280px;
  height: 24px;
  position: absolute;
  overflow: hidden;
  border-right: 1px solid #D31A47;
}

.filling {
  width: 280px;
  height: 24px;
  position: absolute;
  background: linear-gradient(to right,#31C4F3 20%,#F16172 20%,#F16172 98%,transparent 98%
  );
  animation: slideInFill 1s ease-in forwards; 
  border-top-left-radius: 16px;
  border-bottom-left-radius: 16px;
  padding: 1px;
  background-clip: content-box;
  box-sizing: border-box;
}
<div class="container">
    <div class="borders">
        <div class="borders-fill-1 animate"></div>
        <div class="borders-fill-2 animate"></div>
    </div>
    <div class="fill-bg"></div>
    <div class="filling">
    </div>
</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-