尝试调用 HTMLElement.style 时背景简写属性的值错误地扩展
P粉269530053
P粉269530053 2023-09-03 21:10:48
0
2
324
<p>在元素的样式中,我有一些内联 CSS 声明,包括背景的简写声明</p> <pre class="brush:php;toolbar:false;"><style> :root{ --bg-white: rgba(255, 255, 255, 0); } </style> <div style="background: var(--bg-white); ... "></div></pre> <p>但是当迭代 HTMLElement.style 时,速记属性看起来像是错误扩展的</p> <pre class="brush:php;toolbar:false;">for (const declaration of Array.from(target.style)) { const value = target.style.getPropertyValue(declaration) console.log(`${declaration}: ${value}`) }</pre> <p>这应该根据 MDN 上的 HTMLElement.style 文档打印出 <code>background-color: var(--bg-white)</code> ,但我得到 <code>background-color: ''</code> </p> <blockquote> <p>扩展了简写属性。如果设置 style="border-top: 1px Solid black",则会设置普通属性(border-top-color、border-top-style 和 border-top-width)。</p> </blockquote> <p>有人遇到过这种情况吗?</p>
P粉269530053
P粉269530053

全部回复(1)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!