html - random default thumbnail for blogger -


i'm learning html , css. i'm working on blogger blog template.

my template has front page of post thumbnails.

i have set class default thumbnail when posts not have image , have set url in css.

.altthumbnails {    background: url(myimagelocation.jpg);   } 

is there way can make more 1 default thumbnail? chose maybe 3 images show @ random when there no post image.

thanks replies

you can not pure css. can either server-side code use or js 1 suggest. basicly 1 of easiest solution can make different classes each different image wanna use, can produce random number in js , use number apply different classes elements. here's example:

demo

in example there 5 different css class supply 5 different background-image , names end numbers 1 >> 5.

.thumb_1 { .. } .thumb_2 { .. } .thumb_3 { .. } .thumb_4 { .. } .thumb_5 { .. } 

in javascript we're gonna loop through objects, generate random number 1 >> 5 , use number add new class this.

var div = document.getelementsbyclassname("thumb");  //var rand = math.floor(math.random() * 5 ); // 1 image  (var = 0; < div.length; i++){    var rand = math.floor(math.random() * 5 ); // multiple images    div[i].classname += " thumb_" + (rand + 1) ; }; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -