How can I show the value of an attribute as text using CSS?

3

I want to show the value of an attribute as text.

<div title="12:56pm">
    <span data-measureme="1">
        <span>hi</span>
    </span>
</div>

Example that does not work in jsFiddle .

Something like

div > span:before {
    content: parent.title;
}

Is it possible to do this with CSS? How / Why?

On browser compatibility, I just need it to run in the latest version of Chrome and Firefox. But if there is a solution that works in any browser it would be cool.

    
asked by anonymous 23.12.2013 / 16:18

2 answers

8

CSS still does not have a way to access attributes of a parent element. However, an attribute can be obtained through attr() , documented here in English . / p>

content: attr(title);

In this way the only way is to adapt the selector to get the element containing the property.

div:before {
    content: attr(title);
}

See the example in jsFiddle .

    
23.12.2013 / 16:36
1

Maybe if you put value or placeholde r. Your question was confusing.

    
21.09.2016 / 19:17