r/csshelp • • May 26 '14

Replace words with ***

Is there a way to replace a certain word with asterisks?

So, if the word is "hello," when someone types it, it would replace it with h****.

Not sure if that's doable. Thanks!

10 Upvotes

2 comments sorted by

6

u/steve_abel May 26 '14

Not with css.

3

u/jaredcheeda May 26 '14 edited May 26 '14

with css you can target html tags, for example

<p>This is a paragraph wrapped in a p tag</p>
<p>This is another with a <strong>bold</strong> word inside it</p>

So that's your html, now css can target the TAGS, not the CONTENT. example:

p { background-color: red; }
strong { font-weight: bold; }

That's the basics anyways. We've added some more advanced stuff too. So we can target not just tags, but tags that have specific ATTRIBUTES, but again, NOT the content. Example:

<a href="google.com">This is a link</a>
<a href="reddit.com">Another link with a <strong>bold</strong> word</a>

So now I can make ALL links underline, google links blue, reddit links red, and ONLY bold words that are linking to reddit extra large.

a { text-decortation: underline; }
a[href="google.com"] {color: blue;}
a[href="reddit.com"] { color: red; }
a[href="reddit.com"] strong { font-size: 30px; }

For something more advanced, you could actually add in content BEFORE or AFTER a selected target.

a:after { content: "potato"; }

Now all links on the page will have the word potato after them, you could also do before instead.


And you can get more specific. So if your html was:

<a href="reddit.com">I like <strong>fried</strong></a>

Then you could make it so ONLY bold words that are being linked to reddit.com will be targeted, and have them add the word potato after the bold word, but still inside the link.

a[reddit.com] strong:after { content: "potato"; }

That's about the extent of what you can do. You can't target content, only markup. Though you can inject images as background elements of your :after or :before elements. This is how some subreddits allow for inline images in comments.

With javascript you can target markup like this, or content. And of course so can other higher languages (python, ruby, asp.net, php, java, etc.)

For the purposes of editing reddit stylesheets though, you only have access to CSS2 and very limited parts of CSS3. Watch my video in the sidebar for more information about how to work with reddit's stylesheets. It's the second guide.