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
}
``
关于html - CSS中获取div、button等的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58245890/