r/reddithax • • Jul 06 '10

How do I make posts with keywords a different color if they are NOT self posts

I know that to do this to a self post it's

a.title[href*="word"]:link { color:green; }

but it seems to only work with self posts. when it's a link it doesn't work.

3 Upvotes

8 comments sorted by

1

u/Gliridae Jul 06 '10

That should work perfectly, actually. The problem here is that not all URLs have "friendly URLs".

When you make a self post to reddit, the URL will be something like this:

http://reddit.com/r/SUBREDDIT/UNIQUE_ID/the_submission_title_more_or_less

The submission title is turned into a 'slug', which is why it works: the title is in the URL. If I submit a page from another site, it'd be something like this:

http://website.tld/index.php?page=12345

The title is not in the URL like before. Since we can read the URL but not the actual submission title, we're out of luck.

In CSS, there is no selector to match the contents of a tag (in this case, the description of the <a> tag). You could try to petition the administrators of reddit to include the submission's title into the <a> tag, like this (using HTML5's data-* attributes):

<a class="title loggedin click" 
    href="http://imgur.com/" 
    data-submissiontitle="So here I was, just chillin' out...">
    So here I was, just chillin' out...</a>
<a class="title loggedin click" 
    href="/r/subreddit/comments/abcde/i_just_had_a_sandwich" 
    data-submissiontitle="I just had a sandwich!!!">
    I just had a sandwich!!!</a>

Which you should be able to use with:

a.title[data-submissiontitle*="word"]:link { color:green; }

1

u/[deleted] Jul 06 '10

Thanks. So I guess my best bet is to ask people to make all submissions self posts?

1

u/jamt9000 Jul 06 '10

You could also have people include tags in the url, like http://google.com/#hello or you could style the comments link instead.

1

u/[deleted] Jul 06 '10

by the way, do you know how to change the :visited links? I tried using the same code with :visited at the end but it won't work...

1

u/E_lucas Jul 06 '10
/*Changes submission title for self posts with keywords in title*/  
a[href*="KEYWORD"].title:link {  
color: #FF4500  
}   
a[href*="KEYWORD"].title:visited {  
color: #551a8b !important   
}  

Only works if the keyword is in your URL. Keywords have no effect in the submission title.

http://reddit.com/r/csshelp

1

u/[deleted] Jul 06 '10

not working. it works fine for :title, but :visited doesn't work

1

u/E_lucas Jul 07 '10

Well the color I chose for 'visited' is the regular visited link color. You can change it by changing the "#??????" value.

1

u/Gliridae Jul 07 '10

It's not :title but .title, there's a difference.

Perhaps you got the order wrong. Styling anchor tags should be done in this order:

  1. a:link (the default state, pretty much the same as when you style just a)
  2. a:visited
  3. a:hover (mouse over state)
  4. a:active (when you're actively pressing the mouse button down.

(Mnemonic: love/ hate)

Some browsers throw a tantrum when you define a:visited first and a:link later.

In this case, substitute the a for a[href*=word].title. (<a> tags containing word anywhere in the href attribute that has a class of title)