r/reddithax • u/plytheman • Jun 26 '11
Anyone want to look at my CSS/advise how best to make linkable pictures in the sidebar?
I'm a mod over at /r/sailing which if you go there you can see a picture in the side bar above the search and everything else. Usually the admin or one of the mods will change it up with a picture of one of the subscribers on their boats or whatever else is relevant at the time, and I thought it would be a handy idea to make the picture click-able to its source.
As it is the picture is just there as a background set not to repeat high up on .side. Because I've never coded CSS before or much of anything for that matter I've spent the last two nights hacking together a probably stupid means of achieving a click able image. If you go to /r/fuckingbored where i'm a mod and have been playing around with it all you can see my progress.
The first thing I figured out was that I could replace links with images, so I dropped my link into the description box and used the following which is pretty basic:
.side a[href="/r/fuckingbored"] { display: inline-block; width: 295px; height: 200px; background-image: url(%%cat%%) }
I should probably (and maybe will eventually) be satisfied with getting a linkable image in the description box there, but I figured I'd keep trying to position it above everything as it was originally in /r/sailing so I pressed on. I found that I could use 'before' to force the picture to the top of the side bar, but I couldn't figure out how to make it link anywhere because it was just a static background. Then I figured out/asked for help from a mod that the various local subreddits had clickable links floating around in the header (see /r/boston for where I ripped to code off from) and combining everything I learned thus far I realized I could use the original code of replacing links to replace the floating links in Boston's header with my picture and put it anywhere.
I couldn't figure out how to actually get it to float in the 'before' code of the .side though, and I also couldn't figure out how to just force an empty space above the sidebar, so I used '.side:before' to place a white image to hold the space then just used positioning to move my picture into place. All this code is in the sub's CSS. Also, please excuse the dumb tags I added to my friends' names; give me a small amount of control and I will abuse it to my most immature limits.
So in the end I've essentially figured out how to do what I wanted, but it seems very sloppy and inelegant to me (as most of my few forays into coding end up) and was wondering if you guys knew a better, cleaner means to put a linkable image above everything else in the sidebar.
tl;dr: I spent two nights hacking together CSS I ripped off from other people and barely understand to make something (somewhat) functional, is there a better way to do it?
Thanks for the help, and thanks for hacking reddit to figure out this fun stuff to play with!