- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我为自己制作了一个进度条,让我的客户可以看到进度。当您检查我的代码时,您可以看到我构建它的方式可以将 li::after
元素的 width
设置为 0 - 100%,这应该定义每个步骤的进度。
现在我遇到的问题是,当我最小化窗口时,第一个 li
的 ::after
元素破坏了 next li
这不好。它应该最小化并且只填充每个元素之间可用空间的宽度。
因此,例如,当第一步是 40 %
完成时,::after
应该将宽度更改为 40 %
:
当宽度 get 更改为 60 %
时,绿色的 ::after
元素更接近下一步。当您现在最小化窗口并将 40 %
设置为第一个 ::after
元素时,它的宽度不会随着新窗口大小而改变,并且会破坏下一个元素应该避免。这是我的问题。
我试了很多,但我还是不明白。那么我该如何解决这个问题呢?
.progress-container {
position: relative;
}
.progress-container::before {
background-color: #dadada;
width: 80%;
height: 11px;
position: absolute;
left: 10%;
right: 10%;
top: 53px;
content: '';
}
.progress-bar {
list-style: none;
margin: 0;
padding: 0 !important;
display: flex;
display: -ms-flexbox;
justify-content: space-between;
width: 100%;
color: #666666;
font-size: 2em;
}
.progress-bar h3 {
font-size: 18px;
letter-spacing: 2px;
}
.progress-bar li {
position: relative;
display: inline-block;
text-align: center;
font-size: 0.6em;
padding-right: 1em;
}
.progress-bar li::before {
content: attr(data-step);
display: block;
background: #666666;
color: #ffffff;
width: 7em;
height: 7em;
text-align: center;
margin: 0 auto 20px;
line-height: 7em;
border-radius: 100%;
position: relative;
z-index: 1000;
}
.progress-bar li::after {
content: '';
position: absolute;
display: block;
height: 11px;
top: 53px;
left: 50%;
margin-left: 2.9em;
z-index: 2;
}
.progress-bar li.progress-1.is-active::before,
.progress-bar li.progress-1.is-active::after {
background: green;
}
.progress-bar li.progress-1::after {
width: 40%;
}
.progress-bar li.progress-2.is-active::before,
.progress-bar li.progress-2.is-active::after {
background: yellow;
}
.progress-bar li.progress-3.is-active::before,
.progress-bar li.progress-3.is-active::after {
background: orange;
}
.progress-bar li.progress-4.is-active::before {
background: red;
}
.progress__last {
padding-right: 0;
}
.progress__last:after {
display: none !important;
}
<div class="progress-container">
<ol class="progress-bar">
<li class="progress-1 is-active" data-step="1">
<h3>1</h3>
</li>
<li class="progress-2 is-active" data-step="2">
<h3>2</h3>
</li>
<li class="progress-3 is-active" data-step="3">
<h3>3</h3>
</li>
<li class="progress-4 progress__last is-active" data-step="4">
<h3>4</h3>
</li>
</ol>
</div>
最佳答案
我会像下面这样简化代码并使用一些背景技巧。这个想法是在主要元素上使用背景着色来定义百分比。
为了方便起见,我还使用了 CSS 变量。
.progress-container {
margin:5px;
}
.progress-bar {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
color: #666666;
background:
/*The gradient that will hide the main one based on the percentage*/
linear-gradient(#dadada,#dadada) 100% 30px/ calc(100% - var(--p,100%)) 10px,
/*the main gradient with 3 colors*/
linear-gradient(to right,
green 0 ,green calc(100%/3),
yellow calc(100%/3) ,yellow calc(2*100%/3),
orange calc(2*100%/3),orange calc(3*100%/3))
0 30px/100% 10px;
background-repeat:no-repeat;
position:relative;
z-index:0;
}
.progress-bar h3 {
font-size: 18px;
letter-spacing: 2px;
}
.progress-bar li {
display: inline-block;
text-align: center;
font-size: 1em;
padding-right: 1em;
}
.progress-bar li:first-child {
margin-left:-5px;
}
.progress-bar li:last-child {
padding-right:0;
margin-right:-5px;
}
.progress-bar li::before {
content: attr(data-step);
display: block;
background: #666666;
color: #ffffff;
width: 4em;
height: 4em;
text-align: center;
line-height: 4em;
border-radius: 50%;
}
.progress-bar li.progress-1.is-active::before {
background:green;
}
.progress-bar li.progress-2.is-active::before {
background: yellow;
}
.progress-bar li.progress-3.is-active::before {
background: orange;
}
.progress-bar li.progress-4.is-active::before {
background: red;
}
<div class="progress-container">
<ol class="progress-bar" style="--p:20%">
<li class="progress-1 is-active" data-step="1" >
<h3>1</h3>
</li>
<li class="progress-2" data-step="2">
<h3>2</h3>
</li>
<li class="progress-3" data-step="3">
<h3>3</h3>
</li>
<li class="progress-4 progress__last" data-step="4">
<h3>4</h3>
</li>
</ol>
</div>
<div class="progress-container">
<ol class="progress-bar" style="--p:50%">
<li class="progress-1 is-active" data-step="1">
<h3>1</h3>
</li>
<li class="progress-2 is-active" data-step="2" >
<h3>2</h3>
</li>
<li class="progress-3" data-step="3">
<h3>3</h3>
</li>
<li class="progress-4 progress__last" data-step="4">
<h3>4</h3>
</li>
</ol>
</div>
<div class="progress-container">
<ol class="progress-bar" style="--p:75%">
<li class="progress-1 is-active" data-step="1">
<h3>1</h3>
</li>
<li class="progress-2 is-active" data-step="2" >
<h3>2</h3>
</li>
<li class="progress-3 is-active" data-step="3">
<h3>3</h3>
</li>
<li class="progress-4 progress__last" data-step="4">
<h3>4</h3>
</li>
</ol>
</div>
<div class="progress-container">
<ol class="progress-bar" style="--p:100%">
<li class="progress-1 is-active" data-step="1">
<h3>1</h3>
</li>
<li class="progress-2 is-active" data-step="2" >
<h3>2</h3>
</li>
<li class="progress-3 is-active" data-step="3" >
<h3>3</h3>
</li>
<li class="progress-4 progress__last is-active" data-step="4">
<h3>4</h3>
</li>
</ol>
</div>
关于html - CSS:当浏览器窗口大小发生变化时,如何使伪元素宽度动态变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53923462/
如标题所示,我正在寻找有关伪/冒号 header 字段用途的一些信息,即我想知道为什么我们有第二种类型的 header 字段... 另外 - 我知道在 http2 中使用伪/冒号 header 字段代
(伪)多线程:借助外力 利用WEB服务器本身的多线程来处理,从WEB服务器多次调用我们需要实现多线程的程序。 QUOTE: 我们知道PHP本身是不支持多线程的, 但是我们的WEB服务器是支持多线程的
您如何在 HDL (verilog) 中实现硬件随机数生成器? 需要考虑哪些选项? 这个问题是在self-answer之后格式。鼓励添加答案和更新。 最佳答案 正如摩根的回答中所指出的,这只会产生一个
我写了这个CSS: div { width: 500px; height:150px; margin-left:150px; background: lightblue; } div:
这是我要解决的问题:从数据库A读取一个字符串,将该字符串转换为Date对象,将Date对象存储到数据库B中。 例)数据库A:从数据库A读入日期字符串“ 2015-03-08 02:00:00”,转换为
我想创建 std::fscanf() 的 sibling (我知道这是一个 C 函数)。所以,我的界面是这样的: template std::size_t ts_scanf(is, format,
运行 PostgreSQL 7.x(是的,我正在升级) 问题: 如果没有返回数据,我有三到四个字段需要设置。 正在考虑这样的事情 SELECT CASE WHEN default_fie
出于某种原因,我很难在 JS 中为我的游戏执行以下代码: 假设我们要求用户在棋盘上移动一个棋子。他们可以做的位置是位置A、位置B或位置C。每个位置一次只能容纳一件。否则为无效移动。 第一个用户决定
我已经毫无问题地编写了霍夫曼树的代码,但现在我希望在文件和树中添加伪 EOF,以便我知道何时停止从文件中读取。 我完全掌握了伪 EOF 的概念。我还了解到没有 ASCII 值 > 255 的字符。 我
给定一个按钮 ::after 当被触发时,伪 :after 类需要有一个类 search-active 切换,为按钮设置背景颜色 .primary .search:after, .primary
我想让第一行的文本像第二行一样缩进 (50px)。有什么办法吗?非常感谢! body{ counter-reset: h2counter; } h1{ counter-reset: h2counter
:before 或 :after 这样的伪元素是否可以从父元素的不同属性继承值? 在我的例子中,我有一个第三方组件设置其元素运行时的背景颜色...我需要继承该颜色并将其设置为伪元素的边框颜色。 最佳答
在并行循环中请求随机数总是返回相同的伪随机数。我怎样才能避免这种情况? % workers initialization: if matlabpool('size') == 0 matlabp
假设最大IP可以包含每个“点”括号中的最大数量999,即999.999.999.999 是最大的可用值。 我已经在计算器中检查了正则表达式 ([0-9]+.){3}[0-9]。那么,为什么程序抛出运行
我对随机数生成的概念非常陌生,我需要为用c编写的工作创建自己的算法(内置的随机数生成器对我不起作用)。 有人能给我介绍一个很好的主题,这样我就可以理解这个概念了吗?到目前为止,我所发现的一切似乎都是用
假设我有一个数字序列:{n, n+1, n+2, ... n+m} 在不提前存储数字的情况下,我想创建一个函数 f(),给定序列 {1,2,3,...m} 将以随机(或至少伪)的方式吐出原始集合随机)
什么是伪 tcp channel ,如何实现? 最佳答案 伪 TCP 是一种协议(protocol),它实现了 TCP 的一些思想,以通过不可靠的、基于数据包的接口(interface)提供可靠的数据
我正在尝试展开一些嵌套循环,以牺牲内存为代价(可能)获得更好的性能。在我的场景中,我最终会得到一个包含大约 3 亿个元素(元组)的列表,我必须以(或多或少)随机顺序产生这些元素。 在这个数量级上,ra
如何在 PHP 中生成(伪)随机字母数字字符串,例如:'d79jd8c'? 最佳答案 首先创建一个包含所有可能字符的字符串: $characters = 'abcdefghijklmnopqrstu
我有一段代码可以为玩家生成迷你任务。这很简单,要获得两个不同的点(起点和终点),我有一个如下所示的算法: std::vector missions; missions.push_bac
我是一名优秀的程序员,十分优秀!