r/csshelp • • Jul 07 '16

Reddit logo randomly changing?

Is there any way to make it so that my reddit logo can change image randomly? Like on subreddits where their sidebar image changes every time you refresh the page.

6 Upvotes

7 comments sorted by

2

u/gavin19 Jul 07 '16

You can see a basic example at /r/csshelpcss10 using plain colours. CSS is at the bottom of the stylesheet.

It'll need tweaked depending on the size of your images and the height of your header.

1

u/TheMegatoaster9000 Jul 07 '16

It's not working. What do I need to change?

#header-img[class] { background: none; }
input[name=uh] ~ a:after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    height: 130
    margin-right: calc(100vw - 140px);
    width: 169px
    z-index: -1;
}
.res-navTop input[name=uh] ~ a:after {
    bottom: auto;
    top: 5px;
}
input[name=uh][value$="a"] ~ a:after { background: url(%%img%%); }
input[name=uh][value$="b"] ~ a:after { background: url(%%img2%%); }
input[name=uh][value$="c"] ~ a:after { background: url(%%img3%%); }

1

u/gavin19 Jul 07 '16

You're only using part of it. There are 36 of these

input[name=uh][value$="?"] ~ a:after { ... }

One for each of a-z and 0-9. Each page load the CSS will match one of those values. Since you only cover a/b/c, 33 out of 36 page loads will show nothing.

1

u/TheMegatoaster9000 Jul 08 '16

It still doesn't work. I tried using a spritesheet, is that alright?

#header-img[class] { background: none; }
input[name=uh] ~ a:after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    height: 130px
    margin-right: calc(100vw - 140px);
    width: 169px
    z-index: -1;
}
.res-navTop input[name=uh] ~ a:after {
    bottom: auto;
    top: 5px;
}
input[name=uh][value$="a"] ~ a:after { background: url(%%spritesheet%%) -5px -5px; }
input[name=uh][value$="b"] ~ a:after { background: url(%%spritesheet%%) -145px -5px; }
input[name=uh][value$="c"] ~ a:after { background: url(%%spritesheet%%) -285px -5px; }
input[name=uh][value$="d"] ~ a:after { background: url(%%spritesheet%%) -425px -5px; }
input[name=uh][value$="e"] ~ a:after { background: url(%%spritesheet%%) -565px -5px; }
input[name=uh][value$="f"] ~ a:after { background: url(%%spritesheet%%) -5px -184px; }
input[name=uh][value$="g"] ~ a:after { background: url(%%spritesheet%%) -145px -184px; }
input[name=uh][value$="h"] ~ a:after { background: url(%%spritesheet%%) -285px -184px; }
input[name=uh][value$="i"] ~ a:after { background: url(%%spritesheet%%) -425px -184px; }
input[name=uh][value$="j"] ~ a:after { background: url(%%spritesheet%%) -565px -184px; }
input[name=uh][value$="k"] ~ a:after { background: url(%%spritesheet%%) -5px -363px; }
input[name=uh][value$="l"] ~ a:after { background: url(%%spritesheet%%) -145px -363px; }
input[name=uh][value$="m"] ~ a:after { background: url(%%spritesheet%%) -285px -363px; }
input[name=uh][value$="n"] ~ a:after { background: url(%%spritesheet%%) -425px -363px; }
input[name=uh][value$="o"] ~ a:after { background: url(%%spritesheet%%) -565px -363px; }
input[name=uh][value$="p"] ~ a:after { background: url(%%spritesheet%%) -5px -542px; }
input[name=uh][value$="q"] ~ a:after { background: url(%%spritesheet%%) -145px -542px; }
input[name=uh][value$="r"] ~ a:after { background: url(%%spritesheet%%) -285px -542px; }
input[name=uh][value$="s"] ~ a:after { background: url(%%spritesheet%%) -425px -542px; }
input[name=uh][value$="t"] ~ a:after { background: url(%%spritesheet%%) -565px -542px; }
input[name=uh][value$="u"] ~ a:after { background: url(%%spritesheet%%) -285px -721; }
input[name=uh][value$="v"] ~ a:after { background: url(%%spritesheet%%) -705px -184px; }
input[name=uh][value$="w"] ~ a:after { background: url(%%spritesheet%%) -705px -363px; }
input[name=uh][value$="x"] ~ a:after { background: url(%%spritesheet%%) -705px -542px; }
input[name=uh][value$="y"] ~ a:after { background: url(%%spritesheet%%) -5px -721px; }
input[name=uh][value$="z"] ~ a:after { background: url(%%spritesheet%%) -145px -721px; }
input[name=uh][value$="0"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="1"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="2"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="3"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="4"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="5"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="6"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="7"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="8"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }
input[name=uh][value$="9"] ~ a:after { background: url(%%spritesheet%%) -705px -5px; }

}

1

u/gavin19 Jul 08 '16

You forgot the semi-colon on the height/width lines.

Also, the snoo is 40px tall by default, but yours are 130px. So, you need to make the header taller to accommodate that. Add

#header {
    background: crimson;
    height: 160px;
}
#header-bottom-left {
    position: absolute;
    bottom: 0;
}