html - CSS中获取div、button等的宽度

标签 html css

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/

相关文章:

html - anchor 标签的目标属性的正确方法是什么?

html - map /区域周围的阴影

css - 响应式样式 : Using the @media tag for moving text-box below img (margins)

html - 如何使 div 在 HTML 中居中​​对齐

PHP imap,来自 Mailbody 的 CSS 破坏网站布局

jquery - gmaps 上方的 float 滑动切换菜单

jquery - 单击图像下方具有较高 z-index 的内容

ios - Cordova:我可以在 div 中显示 native 应用程序组件吗?

html - IE11/Edge 中的可滚动 Flex-box Child 问题

javascript - 如何防止 tr 的背景颜色溢出到禁用的输入字段中