Change Background with CSS on particular date?

后端 未结 4 817
灰色年华
灰色年华 2021-01-14 01:40

Does anyone know how to change the background of a website automatically using CSS on specific dates? Like valentines, easter, xmas etc.

4条回答
  •  灰色年华
    2021-01-14 02:33

    You wont be able to do it using only css but you could do it combining javascript and css like so,

    var checkDate=new Date(),
    today = new Date();
    checkDate.setFullYear(2011,1,14);
    
    if (today.getTime() === checkDate.getTime()){
        document.getElementById("background").className += 'valentinesBackgroundStyle';
    }
    

    http://jsfiddle.net/sH429/

提交回复
热议问题