Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show an attribute as text with CSS?

Tags:

html

css

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

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

        <span>hi</span>

    </span>
</div>

Not working example on jsFiddle.

Something like

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

Is it possible to do it with CSS? How/why?

About browser compatibility, I only need it to run on latest Chrome and Firefox. But if there is a solution that could work on any browser it would be nice.

like image 705
BrunoLM Avatar asked Dec 23 '13 15:12

BrunoLM


1 Answers

There is a way of using attributes as you're describing in CSS. You'll simply use:

content: attr(title);

However, the issue you're having in your code is that you can only use this attr() function on the element being referenced. In your case, the span doesn't have a title attribute. You might want to consider reworking your code to allow for something such as:

div:before {
    content: attr(title);
}
like image 200
Brian Phillips Avatar answered Sep 22 '22 18:09

Brian Phillips