【问题标题】:How do I read the height or width property of pseudo-element :before using Javascript?如何读取伪元素的高度或宽度属性:在使用 Javascript 之前?
【发布时间】:2012-03-29 10:38:14
【问题描述】:

我需要计算一个由伪类:before创建的元素的新位置。

这个元素是一个 li 标签,我在其中显示属性 alt。 宽度和高度取决于包含属性 alt 的文本的长度。

CSS:

.legende:before{ 
position:absolute;
max-width:70%;
bottom:0.2em;
z-index:1;
padding:0.3em 1em;
font-size:1.6em;
content:attr(alt);
}

有可能这样做吗?我该怎么做?

【问题讨论】:

标签: javascript css pseudo-element


【解决方案1】:

不,一个伪元素属于它的“宿主”元素的盒子,所以最好的办法是查询宿主元素本身的offsetWidth/offsetHeight

【讨论】:

    猜你喜欢
    • 2022-11-04
    • 2014-06-08
    • 1970-01-01
    • 2021-10-30
    • 2017-10-02
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多