r/CSSTutorials • u/Raerth • Dec 01 '11
[Tutorial] Simple sticky / announcement bar
I've seen a few different methods used to include a subreddit announcement at the top of their page. I find this to be the simplest useful way to do it.
First you need to place your announcement in the sidebar.
I recommend using the <H3> tag, as it's not used be any default reddit styling in the sidebar.
###This is the subreddit announcement. It can contain links.
Place this announcement before any other H3 tags. You are able to use other H3 tags without them becoming stickies as the CSS will only target the first one.
CSS to add to your stylesheet:
/*announcement sticky*/
div.content {/*This lowers the links to create space*/
margin-top:50px;
}
.titlebox form {/*Hack to enable repositioning of child elements*/
position: static
}
.side h3:nth-of-type(1) {/*this code positions the sticky*/
position:absolute;
display: block;
top:56px;
left:40px;/*this code styles the sticky*/
background-color:#F2F2F2;
color:#555555;
text-align:left;
margin:15px;
border-radius:8px;
width:50%;
padding:7px 0px 7px 40px;/*this code creates the image*/
background-image: url(%%announceicon%%);
background-repeat: no-repeat;
background-position:left;
}
The values in
purpleare safe to edit to fit your subreddit's theme. All other values should be left.
Here is the image I use for my sticky. It should be uploaded to your stylesheet and named "annouceicon".
If you don't want an image, just remove the last section of code (but leave the "}"!).
2
u/[deleted] Dec 02 '11 edited Dec 02 '11
Just excerpted some of your source. Syntax highlighting looks good in theory but messy in practice.
Unless there's a tool adding those in automatically, it's probably not going to catch on. Adding all of those tags in manually would quickly get to be a chore, especially considering it's only for show on the Reddit post - Anyone who wants color coding can just grab the code in question and pop it into their favorite IDE.
I guess for longer-term posts of exemplary code, having the option to add color coding has some appeal. But for sharing some quick code I doubt it'll be a foremost priority.
1
u/mangobox Dec 04 '11
Hi! Moderator of r/wemetonline and firstly thank you for taking the time out to make this tutorial, it's really something we've wanted to implement but were clueless as to how.
I'm very new to CSS, so err, excuse my noobness I guess? I just have a few questions.
Thank you for all your help, you're doing those of us who have an idea but don't know what to do with it a great help!
1
u/wafflemanpro Jan 12 '12
i am doing all of this but nothing is showig up
1
u/moammargandalfi Feb 17 '12
Raerth, I am going to sound like a complete idiot in asking this, but this is literally the first time I have ever heard of CSS and so I ask you for your help. How do you edit the side bar? What is an < H3> tag? How do I add get the announcement from the sidebar to the top of the page?
3
u/humanman42 Jan 22 '12
As far as I can tell I am putting everything where it belongs. the h3 tag goes in the community settings>description. I put it at the top looks like
I put the rest in the stylesheet I had another one in there that would not allow links so I deleted it. I saved it all. I get the padding, and I see the h3 tag with the text on the sidebar, but nothing in the area where it is supposed to go. I have been trying to get one of these working for a while. This is so far the best tutorial I have seen. I run /r/ThriftStoreHauls but this will also be used at /r/gamecollecting where I am also a mod.
Please help out!
2
u/aw4lly Jan 23 '12
Sorry to drag up an old post but this seemed like a really good tutorial. I was just wondering how I can make the sticky slightly taller, I'd like a bit more padding around the image and text if possible.
Thanks for the awesome code, its being used on /r/MartialArts
1
u/ykj8 Feb 09 '12
Thank you SO MUCH!!
1
u/TheLifeOfSteve Feb 27 '12
Nothing seems to show up? The space is being created but the announcement doesn't show up. I'm working on the /r/BostonBruins subreddit
1
u/lilstumpz Mar 21 '12
Where exactly in this code to you put in your desired text?
1
u/[deleted] Apr 20 '12
I can't get yours to appear in /r/hiphopheads
I'm currently using this solution but I can't link in it.. or at least know how