Question:
Change text using CSS?
anonymous
2008-03-07 10:12:42 UTC
Is it possible to use CSS to replace certain words in a document with an HTML link?

I have a webpage which contains various usernames within a block of text. I want each username to link to the relevent profile page of that user using a hyperlink. It would be possible to write the link in by hand but when there are a lot of names it is going to take a while.

E.G whenever the word "Bob" is found in a page the CSS replaces it with Bob making a link.

Hope that makes sense

Thanks
Five answers:
pxdphil
2008-03-07 10:19:55 UTC
I would use PHP, using the str_replace() function:



http://uk2.php.net/str_replace



Like so:






$string = "This is the content of the page. Bob wrote this";

$string = str_replace("Bob","Bob",$string);



echo $string;



?>



Will output:



This is the content of the page. Bob wrote this



You'll need to do this for each username. If your usernames are stored in a database you can do this really easily with a while loop.
Nikhil S
2008-03-07 10:22:40 UTC
you certainly cant do that in CSS but you can use JS a bit. It would have been very easy if the usernames were generated by a script like ASP or PHP. Why are you using HTML isnt all this information stored in a DATABASE??

Anyway i feel its possible to use java script's document.write feature to take each username and convert it in to a link. I will need more description on how the user names are displayed.
Spearfish
2008-03-07 10:27:23 UTC
Definitely sounds like a PHP string replace issue, using the variable of the username.
anonymous
2008-03-07 10:21:56 UTC
CSS in tandem with PHP or ASP could do that...you won't be able to pull it off solely in CSS though, as there are not conditional operators for you to use with it. (If anyone says that you CAN use conditional statements, they are talking about a hack that only works with older versions of internet explorer...bad programming to mess with it)
?
2016-09-30 03:15:15 UTC
Use an identity, with the checklist on the precise: #mylist, #mylist ul { (some checklist stuff right here) } #mylist a { font-weight: ambitious; } Then in basic terms use the identity ="mylist" characteristic on the precise-point ul, and it will cascade all the way down to the anchors. this way, you upload the identity in basic terms as quickly as to the checklist, and each little thing below it could have the types utilized.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...