簡體   English   中英

在使用Javascript之前,我該如何讀取偽元素的height或width屬性?

[英]How do I read the height or width property of pseudo-element :before using Javascript?

我需要計算由偽類: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);
}

有可能這樣做,我將如何做?

不,偽元素屬於其“主機”元素的框,因此,最好的選擇是查詢主機元素本身的offsetWidth/offsetHeight

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM