csspseudo-elementantenna-house

CSS pseudo-elements: using attr to refer to an attribute of another element


I'd like to use the ::before pseudoelement to insert some text that is found in another area of the HTML file.

My HTML:

<html>
    <body notetext="Note">
     ...
    <p class="bodytext">Don't press the red button!</p>
    </body>

I can use content:attr to select an attribute of the current element, but is it possible to refer to an attribute of an ancestor element? Like you can in XPath, for example (//body/@notetext)

the non-working CSS I have:

p.bodytext::before {
    content:attr(notetext);
}

I'm using Antennahouse Formatter, for CSS Paged Media.


Solution

  • Antenna House Formatter has an -ah-attr-from() extension function.

    The function prototype is as for attr() but with the addition of a parameter specifying the ancestor element:

    -ah-attr-from( <from-name> , <attr-name> <type-or-unit>? [ , <fallback> ]? )
    

    NB - I'm an employee of Antenna House.