简体   繁体   中英

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

I need to calculate the new position of a element who is created by the pseudo class :before.

This element is a li tag where I display the attribute alt. The width and height depend of the length of the text that contain the attribute 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);
}

Is it possible to do that and how would I do it?

不,伪元素属于其“主机”元素的框,因此,最好的选择是查询主机元素本身的offsetWidth/offsetHeight

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM