gpt4 book ai didi

html - 如何仅使用html和scss在元素前后分配不同的背景颜色?

转载 作者:太空宇宙 更新时间:2023-11-04 05:56:35 24 4
gpt4 key购买 nike

我用CSS做了一个圆圈,给它一个类叫node。然后我使用 ::after 在这个圆上创建一条居中线。

我正在尝试为这个圆的每一侧分配不同的颜色。所以说圆圈的左侧应该有一条灰色线,圆圈的右侧应该有一条蓝色线。

我需要 10 次重复才能上传图片,所以我尝试解释情况。

我曾尝试使用 ::before::after 来确定要使用的颜色,但我无法实现。

.node,
.node-second,
.node-last,
.node-first {
background-color: #b2cae9;
border-radius: 50%;
width: 20px;
height: 20px;
}

.node::after {
content: "";
right: -50%;
right: 0;
top: 50%;
width: 100%;
position: absolute;
border: 2px solid #b2cae9;
z-index: -1;
}
<div class="timeline-wrapper d-flex flex-row align-items-center ">
<div class="timeline-child active d-flex flex-column align-items-center flex-grow-1">
<span class="date">18.01.2019</span>
<span class="node-first"></span>
<span class="text">Lorem İpsum Dot</span>
</div>
<div class="timeline-child active d-flex flex-column align-items-center flex-grow-1">
<span class="date">18.01.2019</span>
<span class="node"></span>
<span class="text">Lorem İpsum Dot</span>
</div>
<div class="timeline-child d-flex flex-column align-items-center flex-grow-1">
<span class="date">18.01.2019</span>
<span class="d-flex flex-grow-1 node"></span>
<span class="text">Lorem İpsum Dot</span>
</div>
</div>

最佳答案

你可以这样试试。我使用了圆形元素,:before 元素用于灰线,:after 元素用于蓝线,并相应地定位了它。您的代码中缺少 :before 元素。我不得不编写 CSS,因为此处的代码片段不支持 SASS,但您可以使用此工具将其转换为 SASS:https://css2sass.herokuapp.com/

html,
body {
height: 100%;
}

.container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}

.circle {
width: 10px;
height: 10px;
border-radius: 50%;
border: 2px solid black; /* Show the Circle */
position: relative;
}

.circle:before,
.circle:after {
content: "";
display: block;
width: 49vw;
height: 3px;
position: absolute;
}

.circle:before {
border-bottom: 4px solid grey; /* Show the blue line */
right: 12px;
}

.circle:after {
border-bottom: 4px solid #B2CAE9; /* Show the grey line */
left: 12px;
}
<div class="container">
<div class="circle">

</div>
</div>

关于html - 如何仅使用html和scss在元素前后分配不同的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57741945/

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