开发者

Can you apply the css rule `content` to child elements?

开发者 https://www.devze.com 2023-03-29 06:27 出处:网络
Can you apply the ccs rule content to child elements? css : a:link:before, a:visited:before{ content: \" \"attr(href)\" \";

Can you apply the ccs rule content to child elements?

css :

a:link:before, a:visited:before{
    content: " "attr(href)" ";
}

html :

<a href="/home">Home</a>

Result :

 -------------
|    /home    |
|    Home     |
 -------------

However I would like to do the following:

html :

<a href="/home"><span>home</span></a>

With the previous css the href value would appear before the span.

Is it poss开发者_C百科ible to make it appear in the span?

I've tried this. It's for a sitemap.


No, that's not possible.

To make generated content render inside the span, you need a:link span:before.

Unfortunately, in that case, content: " "attr(href)" "; will no longer work, because the a element is no longer the subject of the selector - the span is, and the span does not have the href attribute.


It is not possible because attr(...) works only for the element itself but you actually need something like this:

a:link > span:before { content: " "parent.attr(href)" "; }

But no such thing as parent.attr() in CSS.

0

精彩评论

暂无评论...
验证码 换一张
取 消