r/csshelp • • Feb 19 '16

How do I make an interactive banner?

I see /r/LosAngelesRams and I want to create something like that for my subreddit. Any ideas how? For /r/STLSports

7 Upvotes

6 comments sorted by

4

u/gavin19 Feb 20 '16

There are plenty of ways to go about it but they use spritesheets, like this.

The gist is that they make a list of links in the sidebar, assign each of them a portion of the spritesheet as the background image, and position them in the header. Each link has a fixed height applied so it only shows the top portion of the image (number). When they're hovered, the height is increased so all of the image is revealed.

I've made a version of it here. I've used different markdown so it doesn't show in the sidebar for those with styles disabled. It's an h5 (#####), followed by a series of empty links

 #####[](//example.com/?7)[](//example.com/?28)[](//example.com/?29)[](//example.com/?74)[](//example.com/?75)[](//example.com/?78)[](//example.com/?80)[](//example.com/?85)

The links are just dummies, but you can use any.

The CSS they use is

.side .titlebox .usertext-body .md ol {
    position: absolute;
    display: block;
    margin: 0!important;
    padding: 0!important;
    top: 28px!important;
    right: 20px!important;
    min-width: auto!important;
    height: auto!important;
    z-index: 499!important;
}
.side .titlebox .usertext-body .md ol:first-child {
    clear: left!important;
    overflow: hidden!important;
}
.side .titlebox .usertext-body .md ol:last-child {
    clear: left!important;
    overflow: hidden!important;
}
.side .titlebox .usertext-body .md ol li {
    float: left!important;
    margin-right: 4px!important;
    padding-top: 5px!important;
    list-style: none!important;
}
.side .titlebox .usertext-body .md ol li:last-child {
    margin-right: 0!important;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Bob_Waterfield"] {
    background: url(%%retired-numbers%%);
    background-position: -2px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Bob_Waterfield"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -2px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Marshall_Faulk"] {
    background: url(%%retired-numbers%%);
    background-position: -63px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Marshall_Faulk"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -63px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Eric_Dickerson"] {
    background: url(%%retired-numbers%%);
    background-position: -125px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Eric_Dickerson"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -125px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Merlin_Olsen"] {
    background: url(%%retired-numbers%%);
    background-position: -187px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Merlin_Olsen"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -187px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Deacon_Jones"] {
    background: url(%%retired-numbers%%);
    background-position: -249px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Deacon_Jones"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -249px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Jackie_Slater"] {
    background: url(%%retired-numbers%%);
    background-position: -313px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Jackie_Slater"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -313px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Isaac_Bruce"] {
    background: url(%%retired-numbers%%);
    background-position: -375px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.45s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Isaac_Bruce"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -375px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Jack_Youngblood"] {
    background: url(%%retired-numbers%%);
    background-position: -438px -15px;
    width: 48px;
    height: 26px;
    padding-right: 8px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}
.md ol li a[href$="https://en.wikipedia.org/wiki/Jack_Youngblood"]:hover {
    background: url(%%retired-numbers%%);
    background-position: -438px -15px;
    width: 48px;
    height: 197px;
    display: block!important;
    text-indent: -9999px;
    transition: all 0.4s ease-out;
}

but all we need is

.side .md h5 {
    position: absolute;
    top: 20px;
    right: 0;
    z-index: 99;
}
.side .md h5 a {
    background: url(%%rams%%);
    display: inline-block;
    height: 30px;
    margin: 0 3px;
    width: 50px;
    vertical-align: top;
    -webkit-transition: .6s;
    transition: .6s;
}
.side .md h5 a:hover {
    height: 200px;
}
.side .md h5 [href="//example.com/?7"] {background-position: -8px -13px;}
.side .md h5 [href="//example.com/?28"] {background-position: -70px -13px;}
.side .md h5 [href="//example.com/?29"] {background-position: -131px -13px;}
.side .md h5 [href="//example.com/?74"] {background-position: -191px -13px;}
.side .md h5 [href="//example.com/?75"] {background-position: -255px -13px;}
.side .md h5 [href="//example.com/?78"] {background-position: -318px -13px;}

and it does the same job. The rams image referenced is their own spritesheet that I uploaded to that test sub.

Note - when you change a link in the sidebar, like

[](//google.com/something)

in place of one of the others, like

[](//example.com/?7)

you need to change that matching reference in the CSS. So

.side .md h5 [href="//example.com/?7"] {background-position: -8px -13px;}

would become

.side .md h5 [href="//google.com/something"] {background-position: -8px -13px;}

1

u/[deleted] Feb 20 '16

My god, this is a huge help! Thank you so much!

1

u/[deleted] Feb 20 '16

I do have one question. Where do I put the series of empty links?

1

u/gavin19 Feb 20 '16

In the sidebar.

1

u/[deleted] Feb 20 '16

Oops! Sorry I didn't see that part.