css - Random Background Image PHP -


i using php code below display random header image every time page refreshed. works fine need add specific background-position css property of images.

for example headerimage3.jpg needs background-position:20px , headerimage1.jpg needs background-position:50px.

is possible using php code below or javascript need used?

<style type="text/css"> #header-image{background:url("/files/headerimage<?php echo rand(1,4)?>.jpg");background-position:center center;background-size:cover}} </style> 

add php header:

<?php     $rnd = rand (1,4);     $pos = ($rnd == 1) ? "50px 0;" : ($rnd == 3) ? "20px 0;" : "top left"; ?> 

then in css:

<style type="text/css"> #header-image {     background-image: url("/files/headerimage<?php echo $rnd ?>.jpg");     background-position: <?php echo $pos ?>;     background-size: cover; } </style> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -