gpt4 book ai didi

css - 自定义大小的线性渐变

转载 作者:行者123 更新时间:2023-12-04 01:11:04 24 4
gpt4 key购买 nike

我有这样的设计:
enter image description here
它已经用 html/css 创建,但我需要删除 1 和 5 的额外 linea。
这是通过添加位置绝对元素来创建灰线来实现的,但容器点的大小是响应式的。
我的想法是为每个容器创建一个背景线性渐变,如下所示:
所有 :

background: linear-gradient(to right, grey 100%, transparent 0);
第一个:
background: linear-gradient(to left, grey 50%, transparent 0);
最后一个:
background: linear-gradient(to right, grey 50%, transparent 0);
但我不知道如何使它变小:
enter image description here

最佳答案

假设所有元素的宽度相等,那么渐变应该从 1 的中点开始并在 5 的中点结束,这意味着它应该从 10% 标记开始到 90% 标记结束,类似于 linear-gradient(to right, transparent 10%, grey 10%, grey 90%, transparent 90%) .
要限制背景的大小,您可以使用 background-size: 100% [DESIRED_HEIGHT]来控制它。假设你想要条形的厚度为 16px,那么你可以使用 background-size: 100% 16px .结合 background-repeat: no-repeat避免梯度重复,以及 background-position: center center将其居中。
请参阅概念验证示例:

body {
font-family: Arial, sans-serif;
}

ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
align-items: center;
justify-content: space-around;

background-image: linear-gradient(to right, transparent 10%, grey 10%, grey 90%, transparent 90%);
background-size: 100% 8px;
background-repeat: no-repeat;
background-position: center center;
}

ul.colors {
background-image: linear-gradient(
to right,
transparent 10%,
red 10%,
red 30%,
orange 30%,
orange 50%,
green 50%,
green 70%,
blue 70%,
blue 90%,
transparent 90%
);
}

ul li {
display: block;
width: 48px;
height: 48px;
border: 1px solid #999;
border-radius: 50%;
background-color: #fff;
display: flex;
align-items: center;
justify-content: center;
}
<strong>Plain</strong>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<br /><br />
<strong>Colors</strong>
<ul class="colors">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>

关于css - 自定义大小的线性渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64824113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com