html - 在 CSS 中获取 div、按钮等的宽度
问题描述
button {
width: auto;
display: inline-block;
(...)
}
button:before {
width: (???);
(...)
}
button:before
当按钮的宽度不固定时,如何获取按钮的宽度?
解决方案
button {
width: auto;
display: inline-block;
position:relative;
(...)
}
button:before {
content:""; *// never forget to put content with empty strings. If you forget it will not work`*
position:absolute; *//set this to position absolute and the parent which is the btn set position:relative*
width:100%;
height:100%; *// if you want the full size of the btn is like this*
top:0;
left:0
}
``
推荐阅读
- nativescript - 将图像绑定到转发器中的图像占位符
- sas - 如何在 SAS 中生成没有输入数据的测试数据?
- r - Restricting loess' multicore usage in R
- python - 如何使用 FileHandler 将变量放入 log_config.yaml - Logging python
- flutter - 当用户使用返回键从任何其他页面返回页面时如何刷新页面?
- scala - 无法从测试中解决依赖关系
- linux - 2个字符串的Grep(或替代),匹配一个,另一个或两者都是成功,包含其他任何内容都是失败
- azure - 在 Azure AD B2C 中使用自定义策略记录对身份提供者的调用
- docker - 在 Kubernetes 上的 lagom 中部署微服务的版本控制
- c# - 如果授权失败并仅返回 401 错误代码,是否可以忽略所有身份验证方案?