html - 带有伪元素的水平居中输入
问题描述
我在这个论坛上搜索了很多这个问题,但似乎还没有答案。
我想创建一个居中输入类型的登录表单checkbox
。我删除了checkbox
使用此代码的正常样式(它是 .scss 代码):
input[type=checkbox] {
margin: auto;
margin-bottom: $fs-h2;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: $fs-h3;
height: $fs-h3;
position: relative;
top: 0;
left: 50%;
transform: translate(-50%);
cursor: pointer;
}
而且我还使用伪元素来分配我自己的样式,使用::before
and ::after
。
现在的问题是,checkbox
没有居中,因为::after
伪元素有一个文本作为内容,它很长并且使用white-space: nowrap
; 在一条线上。
在“父”元素上使用翻译时是否有可能包含伪元素宽度?
这是伪元素的代码:
input[type=checkbox]::before {
content: '';
width: 100%;
height: 100%;
position: absolute;
border: 2px solid $clr-LightBlue;
border-radius: 0.2rem;
transition: all 0.2s ease;
}
input[type=checkbox]::after {
content: 'Benutzerdaten speichern';
position: absolute;
color: $clr-LightBlue;
font-size: $fs-default;
line-height: $fs-default;
transform: translate(25%,25%);
white-space: nowrap;
transition: all 0.2s ease;
}
解决方案
推荐阅读
- python - GET请求:http.client.RemoteDisconnected:远程结束关闭连接没有响应
- linux - 在 Google Cloud VM 上重定向即将到来的请求
- linux - 如何确保手动删除的包不会被恢复?
- eclipse - mac上的svn eclipse使用错误版本的sqlite
- unity3d - Unity3D Cinemachine - 如何锁定敌人的黑暗灵魂风格?
- python - 由于我修改了路径,Jupyter Notebook 中的内核死了
- javascript - Node --inspect 无法识别 JS 中的调试器
- azure-application-insights - 如何使用错误的操作名称汇总 Azure Application Insight 日志
- ios - 展开 UITableViewCell 添加 UICollectionView 作为子视图
- acumatica - 如何在对话框网格上为已发布的材料批次启用自定义字段?