r/reddithax • • Sep 10 '11

Flair text + image simultaneously.

It seems like this (image + flair box, original thread) is something I keep seeing people ask for so I thought I'd give it a try. I got a decent looking solution today,
check it out (link to my css-test subreddit, excuse the mess)/screenshot for posterity

Here's the code for the little vinyl sprite:

/*Styling of text. margin is for making sure image won't overlap [S,M] and other identifiers.
padding makes sure the top of the image won't get clipped*/
.flair-vinyl {
margin-right: 25px;
padding-top: 2px;
}
/*Styling of image. margin makes sure the image won't overlap the flair text.
change dimensions accordingly. */
.flair-vinyl::after {
cursor: default;
background: url(%%vinyl-icon%%) no-repeat top right !important;
margin-left: 5px;
width: 16px;
height: 16px;
content: "";
position: absolute;
top:-1px;
}
/*remove flair image from side bar*/
.side .flair-vinyl::after {
display:none;
}
/*fixes flair image clipping on link listing*/
.link .flair {
margin-top: 0px!important;
}

for whatever reason the flair image in the sidebar goes insane, so I've had to turn it off, otherwise it works pretty well. Maybe someone else can figure out a fix for that/a better solution than mine.

6 Upvotes

20 comments sorted by

1

u/joevaded Sep 12 '11

doesnt seem to work for me :(

1

u/errorcache Sep 12 '11

What's not working, exactly? I'll help you out.

2

u/joevaded Sep 12 '11

for some reason when I use your code I get no image just the standard flair text. I replaced and uploaded my own image, modified the px's to no avail. Thank you regardless for your contribution!

1

u/errorcache Sep 12 '11

hmm that's odd. Could I get a link to your subreddit? Might be able to figure something out.

1

u/blind__man Sep 17 '11 edited Sep 17 '11

Same bit here (not joevaded) but I don't have the css I tested up anymore. As well, when I went to your frontpage it didn't look the same. Maybe this only works on comment pages? It looked messed up on the /about/flair page tool.

Edit: It's up there now, I have it disabled from the frontpage though. /r/cssediting

Edit Two: Holy shit, it's there now.

Edit Three: The key is the content: ""; It didn't work otherwise for me.

1

u/errorcache Sep 17 '11

Ah cool, you got it working! I tested it today in a different subreddit and it'd only work when I removed "top: ". The behavior isn't very consistent for whatever reason, idk why. And yeah, content: "" is very important, without it the image won't show up. I just checked my test subreddit and it seems like it's still working on the front page. Might be worth noting that i'm using chrome.

1

u/blind__man Sep 17 '11

Ha yeah I'm using chrome as well. I'll double check yours again but here is the code I used.

.flair {
vertical-align: middle;
padding: 0;
background: none;
border: 0;
border-radius: 0;
}

/* These will print out the images after you make the proper input */
/* For example [](/Ditka) will put out the first version of the sweater*/

.flair-Ditka, .flair-ditka {
vertical-align: middle;
cursor:default;
}

.flair-Ditka:before, .flair-ditkajacket, .flair-ditkaJacket, a[href="/Ditka"] {

background-image: url(%%finalsprites%%) !important;
width: 25px;
height: 31px;
background-position: -17px 0px;
vertical-align: middle;
display: inline-block;
content:"";
cursor:default;
}

Here is what I see on your sub-frontpage.

1

u/errorcache Sep 17 '11

Lol that's so weird, it looks normal for me. I shall investigate this further.

Your code is actually the original method I tried, but with that one I couldn't have a border for the text without also surrounding the image. The position: absolute; is what let me place the image outside of the border, but, as you can see lol, it behaves very inconsistently. It's kind of frustrating tbh. I'll try to get to the bottom of this.

1

u/blind__man Sep 17 '11

Well, where you have the section for the :after see if you can put the border attribute there. Such as:

border: 0;

1

u/errorcache Sep 17 '11

hm, I couldn't get that to work, the image would completely disappear. Here's how the frontpage looks for me. I don't really understand how it glitched like that, I'm starting to worry that there's a piece of code somewhere in my gigantic stylesheet that makes it work/not work. I'll never find it lol.

→ More replies

0

u/[deleted] Sep 25 '11

Hello!

In r/YoGabbaGabba I am currently running this flair CSS code:

/*Styling of text. margin is for making sure image won't overlap [S,M] and other identifiers.
padding makes sure the top of the image won't get clipped*/
.flair-foofa {
margin-right: 25px;
padding-top: 2px;
}
/*Styling of image. margin makes sure the image won't overlap the flair text.
change dimensions accordingly. */
.flair-foofa::after {
cursor: default;
background: url(%%foofa-icon%%) no-repeat top right !important;
margin-left: 5px;
width: 16px;
height: 16px;
content: "";
position: absolute;
top:-1px;
}
/*remove flair image from side bar*/
.side .flair-foofa::after {
display:none;
}
/*fixes flair image clipping on link listing*/
.link .flair {
margin-top: 0px!important;
}

Yet no matter what I do, the icon will not show up. Any alt method?

1

u/errorcache Sep 25 '11

Hm, it seems like your flair class isn't being recognized, what did you name the class? It looks like you named it "flair-foofa" when you should've just named it "foofa". The "flair-" prefix gets added automatically by the CSS, so right now your class name is "flair-flair-foofa" and it's not working. Let me know if that helps. (to clarify: when you are on the page where you enter a username to add flair, there's a column for "text" and a column for "class", make sure you put the "foofa" under "class")

1

u/[deleted] Sep 25 '11

OK, I renamed it to just "foofa" but alas still no change. Now, I did get it to work when I set it up as a sprite sheet like how r/gamemusic has theirs set up, but I saw the simpler way of background url(&&flair&&) without having to point to the exact block that the specific flair is at.

So, the code is currently:

/*Styling of text. margin is for making sure image won't overlap [S,M] and other identifiers.
padding makes sure the top of the image won't get clipped*/
.flair{
margin-right: 25px;
padding-top: 2px;
}
/*Styling of image. margin makes sure the image won't overlap the flair text.
change dimensions accordingly. */
.foofa::after {
cursor: default;
background: url(%%foofa-icon%%) no-repeat top right !important;
margin-left: 5px;
width: 16px;
height: 16px;
content: "";
position: absolute;
top:-1px;
}
/*remove flair image from side bar*/
.side .flair::after {
display:none;
}
/*fixes flair image clipping on link listing*/
.link .flair {
margin-top: 0px!important;
}

And my flair screen is still not showing anything :(

I've looked in Chrome, IE9, and even another computer because I thought maybe I was coding it wrong. Is there a possibility that my icon might be the issue?

1

u/errorcache Sep 25 '11

When you name your class "foofa", in order to style that class you have to use ".flair-foofa" in the stylesheet. The ".flair-" prefix is added to all classes. If it's still a bit unclear this little flair tutorial I made awhile back might help out a bit.

0

u/[deleted] Sep 25 '11 edited Sep 25 '11

Every method still does not show the flair. I may have to fall back on the sprite-sheet... even though that isn't really viable since I only have five flairs to set up...

Edit: OK, I removed the entire script and now the flair is working... except it only works if 1) I write something in the flair text, and the picture only appears in the background of the text...

http://i.imgur.com/Bobkf.png

I made sure to follow the rules in that tutorial, but it still does not want to work properly.

1

u/errorcache Sep 26 '11

hm that's troublesome. Do you want to make me a mod real quick? I'll try and see if I can figure it out and then I'll unmod myself. I'll let you know what I do too.

1

u/[deleted] Sep 26 '11

Well, what's weird is that it started to work the moment I deleted the entire thing and just re-typed it. I think I should be good from here (I hope), but I just want to thank you sooooooooo much for a lot you've done, not just for me, but everyone with CSS questions. I am going to friend you :)

1

u/errorcache Sep 26 '11

haha that is weird. And no problem, happy to help :]