How to show the width of an element in the content of an ‘:after’ pseudo-element?
I’m looking to show the width of an element within a pseudo element.
so my CSS would look like
but I have no idea if its even possible with just CSS.
If not, how would I do it with jQuery?
It’s currently not possible to do this with CSS alone.
data-width attribute based on the computed width of the element. In doing so, you can use the
content value of
attr(data-width) in order to display this attribute value as the pseudo element’s content. The CSS
attr() function allows you to retrieve the element’s attribute and display the value.
data-width attribute is only set once, you would need to add a
resize event listener in order to set the corresponding width values when they change.