r/csshelp • u/DEADB33F • Feb 08 '12
How to: Display random quotes/images which change every refresh.
Also X-posted to /r/reddithax, but I thought I may as well post it here as well....
Example (stylesheet)
(see the 'Random Headers' Section)
How it works:
- Make an ':after' pseudo-element using the logout button, position & size it where you want it.
- Make another ':after' pseudo-element using a non-clickable element and position it so it covers the first one.
- Check the first character of the hidden modhash input element, style our pseudo-element with text/image based on the character's value.
Step three is repeated 36 times, to cover all the characters 0-9, a-z.
This means you can have up to 36 random images/text strings.
Step two is purely to stop the pseudo-element being clickable. As it's an extension of the logout button normally you'd be able to click it. This isn't desirable.
In theory you could have almost unlimited images/strings by comparing more than just the first character of the modhash. Doing this would give you up to 5036 random images, which is a lot.
1
u/funked_up Feb 08 '12
Is there a way this method can be used to randomize the header background image?
1
u/[deleted] Feb 15 '12 edited Feb 15 '12
Hi, I've been teaching myself CSS in the last 2 months or so and to me, this is really clever, very impressed.
However, from looking at the CSS in the two subs you have listed, I get it completely. What I don't understand is the version being used in /r/Minecraft.
From what I can work out, they are creating a pseudo-class after the container for the submission titles / info, instead of the logout button. I think they are adding this pseudo-class to the second to last .thing in the siteTable, although it is placed behind all other elements and 35% from the right, giving the impression it is a background. Am I right with this?
I think I am right as when you refresh the page multiple times, it does not change until the entries move around due to voting (from what I can tell). Also, when RES never ending scroll generates a new page, the image disappears.
What I don't understand is the [data-fullname$="1"] part, or whatever the corresponding value is. I don't get exactly what it is or how it selects from .thing the value to use. I get why that part exists just not how.
I was wondering if you could enlighten me to this.
Thanks for reading.
1
u/funked_up Apr 24 '12
I've used this random image solution you discovered and it was working great. Recently though, the pseudo-element cover over the random image stopped working. The random images are now clickable and doing so will log you out. Any ideas on how to fix it?
1
u/baconmuffins Feb 27 '12 edited Feb 27 '12
This stylesheet is such a great idea! I have the stylesheet pasted onto the subreddit stylesheep but I'm not sure how to prevent signing out by clicking the quote as far as creating ':after' pseudo-elements. I'm super new to CSS :(
Also, maybe I'm just paranoid but it looks like the first half of the quotes are the only ones that pop up in the corner and the rest of them do not. I have 36 entries and after multiple refreshes, none of the last values entered have popped up.
1
u/Cajoled Feb 28 '12
Hey, how would you move the text so it is on top of an announcement bar (such as the one in /r/gamemaker)? I can't seem to get the text to move. Thanks in advance.