简体   繁体   中英

How to use the 'cite' attribute to display the URL using CSS only?

I need to make a cite attribute visible, ie. showing the url of a blockquote on my webpage. I was told to use only CSS, no html.

Here is what I am currently working with in the html:

<blockquote cite="https://en.wikipedia.org/wiki/History_of_television">
<p>text from wiki</p>

I thought the CSS would be something like: cite href {display: inline-block;} , but that's not working.

I think this is what you're after:

 blockquote:before {
   content: attr(cite);
 }

Here's an example with some additional styling: http://jsfiddle.net/fx4nw3q0/1/

blockquote:after {
  content: attr(cite);
  display: block;
}

You can use attr(<name>) to pull in attribute values into pseudo blocks by the attribute name.

JSFiddle Example

You can show with CSS ::after pseudo-element selector.

blockquote::after{
  content:attr(cite)
}

and you can get url with css attr function ,

DEMO JSBin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM