html - 将伪元素的实际内容居中,而不是伪元素本身
问题描述
这可能吗?如何获取伪元素中心的内容,而不是实际的伪元素本身。我在需要居中的单选按钮上有黑色背景。
请参见下面的示例:
.sizeguide-radio {
width: 3.125rem;
height: 3.125rem;
}
.sizeguide-radio:checked:after {
display: block;
content: '';
width: 50px;
height: 50px;
background-color: black;
color: #fff;
border-radius: 100%;
}
.sizeguide-radio__size:nth-of-type(1):after {
content: '32' !important;
color: #fff !important;
}
.sizeguide-radio__size:nth-of-type(2):after {
content: '34' !important;
color: #fff !important;
}
.sizeguide-radio__size:nth-of-type(3):after {
content: '36' !important;
color: #fff !important;
}
.sizeguide-radio__size:nth-of-type(4):after {
content: '38' !important;
color: #fff !important;
}
.sizeguide-radio__letter:nth-of-type(1):after {
content: 'A' !important;
color: #fff !important;
}
.sizeguide-radio__letter:nth-of-type(2):after {
content: 'B' !important;
color: #fff !important;
}
.sizeguide-radio__letter:nth-of-type(3):after {
content: 'C' !important;
color: #fff !important;
}
.sizeguide-radio__letter:nth-of-type(4):after {
content: 'D' !important;
color: #fff !important;
}
.sizeguide-radio__letter:nth-of-type(5):after {
content: 'DD' !important;
color: #fff !important;
}
label {
display: none;
}
<div class="sizeguide-band-sizes">
<input class="sizeguide-radio sizeguide-radio__size" type="radio" id="32" name="band-size" value="32">
<label for="32">32</label>
<input class="sizeguide-radio sizeguide-radio__size" type="radio" id="34" name="band-size" value="34">
<label for="32">34</label>
<input class="sizeguide-radio sizeguide-radio__size" type="radio" id="36" name="band-size" value="36">
<label for="32">36</label>
<input class="sizeguide-radio sizeguide-radio__size" type="radio" id="38" name="band-size" value="38">
<label for="32">38</label>
</div>
<div class="sizeguide-band-sizes">
<input class="sizeguide-radio sizeguide-radio__letter" type="radio" id="A" name="cup-size" value="1">
<label for="32">A</label>
<input class="sizeguide-radio sizeguide-radio__letter" type="radio" id="B" name="cup-size" value="1/2">
<label for="32">B</label>
<input class="sizeguide-radio sizeguide-radio__letter" type="radio" id="C" name="cup-size" value="2/3">
<label for="32">C</label>
<input class="sizeguide-radio sizeguide-radio__letter" type="radio" id="D" name="cup-size" value="3">
<label for="32">D</label>
<input class="sizeguide-radio sizeguide-radio__letter" type="radio" id="DD" name="cup-size" value="4">
<label for="32">DD</label>
<div>Your size is: <span id="sizeguide-calculated-size">3</span></div>
</div>
content:''
文本偏右,但如果你和相应的position: absolute
样式它会影响整个事情,而不仅仅是文本
这个答案和许多其他人喜欢它的问题:
最好的办法是使用流行的居中技术相对于跨度绝对定位之前的伪元素:
这并没有解决实际的文本。
你如何定位伪元素文本?还是不可能?如果是这样,我该怎么做?
解决方案
尝试将这些行添加到您的 CSS
.sizeguide-radio__size:after,
.sizeguide-radio__letter:after{
display: flex !important;
justify-content: center;
align-items: center;
}
推荐阅读
- javascript - 用三个 js 意外排序反应 mapbox-gl 自定义层
- c# - 使用 BitConverter.GetBytes() 在 C# 中将 Int16 转换为 UByte[] 不起作用
- python - 如何在 Windows 中将凭据设置为环境变量?
- javascript - 尝试使用 Node.js 传递键值对的 EJS 参考错误
- intellij-idea - IntelliJ IDEA 2020.1(终极版)挂了我的Ubuntu 18.04 LTS
- spring - 在使用 @DataJpaTest 时更改 Spring Boot 测试中的刷新模式?
- java - 抽象异常类中的串行版本 uid
- python - 我的 PhotoImage 没有显示在我的窗口中
- unix - sed - 在第一次匹配之前从文件中插入部分
- python - 删除除百分比外的所有括号内的文字