gpt4 book ai didi

javascript - 水平和垂直对齐伪元素的内容

转载 作者:可可西里 更新时间:2023-11-01 12:54:47 24 4
gpt4 key购买 nike

我有以下 css 单选按钮,但它们没有正确对齐。

我想知道如何正确地水平和垂直对齐大圆中的小圆。

.container {
position: absolute;
z-index: 10;
display: -ms-flexbox;
display: flex;
align-items: center;
left: 1.25rem!important;
}

.radio-group__fieldset {
border: none;
padding: 0;
}

.radio-group__options__container {
display: flex;
}

.radio__container {
margin-bottom: 0;
position: relative;
}

.radio__container input[type=radio] {
position: absolute;
cursor: pointer;
left: 0;
top: 0;
z-index: 1;
margin: 0;
zoom: 1;
opacity: 0;
}

.radio__container input[type=radio]:checked+label::after {
opacity: 1;
}

.radio__container label {
position: relative;
font-weight: 400;
color: inherit;
display: -ms-flexbox;
display: flex;
align-items: center;
font-size: 1.25rem;
}

.radio__container label::before {
content: "";
border: 3px solid #0065bd;
border-radius: 50%;
}

.radio__container label::after {
content: "";
position: absolute;
background-color: #0065bd;
border: none;
text-align: center;
border-radius: 50%;
opacity: 0;
}

.radio__inline label {
margin-right: 0.625rem;
}

.radio__container.radio__inline label .radio__content {
margin-left: 0.625rem;
}

.radio__container.radio__small input[type=radio],
.radio__container.radio__small label::after,
.radio__container.radio__small label::before {
width: 13px;
height: 13px;
}

.radio__container.radio__small label::before {
border-width: 2px;
border-radius: 50%;
}

.radio__container.radio__small label:after {
transform: scale(0.8);
}

.radio__content {
display: inline-block;
vertical-align: middle;
position: relative;
top: 10%;
}
<div class="container">
<fieldset class="radio-group__fieldset undefined">
<div class="radio-group__options__container pan-zoom-tree__dependency-filter">
<div class="radio__container radio__small radio__inline">
<input id="depndency-view-0" name="depndency-view" type="radio" value="Activities" checked="">
<label for="depndency-view-0">
<div class="radio__content">Activities</div>
</label>
</div>
<div class="radio__container radio__small radio__inline">
<input id="depndency-view-1" name="depndency-view" type="radio" value="Suppliers">
<label for="depndency-view-1">
<div class="radio__content">Suppliers</div>
</label>
</div>
</div>
</fieldset>
</div>

最佳答案

你可以像这样非常简单:

input {
display: none;
}

label {
display: flex;
position: relative;
padding-left: 30px;
align-items: center;
line-height: 30px;
}
label::before {
content: '';
position: absolute;
left: 0;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid blue;
}

input#r1:checked ~ #l1::before {
background: radial-gradient(blue 0%, blue 40%, transparent 50%, transparent 100%);
}

input#r2:checked ~ #l2::before {
background: radial-gradient(blue 0%, blue 40%, transparent 50%, transparent 100%);
}
<input type="radio" id="r1" name="inp"> 
<input type="radio" id="r2" name="inp">
<label for="r1" id="l1">Radio1</label>
<label for="r2" id="l2">Radio2</label>

这是@TemaniAfif 更简化的方式,而不是 radial-gradient 背景。

input {
display: none;
}

label {
display: flex;
position: relative;
padding-left: 30px;
align-items: center;
line-height: 30px;
}
label::before {
content: '';
position: absolute;
left: 0;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid blue;
padding: 3px;
box-sizing:border-box;
}

input#r1:checked ~ #l1::before,
input#r2:checked ~ #l2::before{
background:blue content-box;
}
<input type="radio" id="r1" name="inp"> 
<input type="radio" id="r2" name="inp">
<label for="r1" id="l1">Radio1</label>
<label for="r2" id="l2">Radio2</label>

关于javascript - 水平和垂直对齐伪元素的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55891683/

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