WordPress.org

Support

Support » Themes and Templates » PHP variable as css value

PHP variable as css value

  • Hi,
    I’m trying to change the value of:

    .entry{
    transform:rotate(<?php echo $random_number; ?>);
    -ms-transform:rotate(<?php echo $random_number; ?>); /* IE 9 */
    -moz-transform:rotate(<?php echo $random_number; ?>); /* Firefox */
    -webkit-transform:rotate(<?php echo $random_number; ?>); /* Safari and Chrome */
    -o-transform:rotate(<?php echo $random_number; ?>); /* Opera */
    }

    on each post in the loop, to turn the thumbnail at a slightly different angle for each post.

    (The to mimic a polaroid being thrown down)

    I’m using this php function:

    <?php $random_number = mt_rand(-20, 20);?>

    Any help would be greatly appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • by the way:
    i tried the method here, to no avail.

    CSS Variables with PHP

    and is this css inline in your template? It obviously wouldn’t work in your style.css but could work if you make it inline.

    i did try, but i was having a very hard time entering/exiting the php and html. (im a graphics guy..lol)

    would you happen to know how to do it?

    i figured i could use

    <?php $random_number = mt_rand(-20, 20);?>
    <div class="entry" style="
    transform:rotate(<?php echo $random_number; ?>);
    -ms-transform:rotate(<?php echo $random_number; ?>); /* IE 9 */
    -moz-transform:rotate(<?php echo $random_number; ?>); /* Firefox */
    -webkit-transform:rotate(<?php echo $random_number; ?>); /* Safari and Chrome */
    -o-transform:rotate(<?php echo $random_number; ?>); /* Opera */

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    but i dont know how to format it for html/php

    I also wanted it to pick a different random number for each post in the loop.

    Thank you very very much for any help you can provide. 😀

    mt_rand is automatically seeded on each execution so u will get a diff number every time when it executes in a loop.

    And take out those CSS comments, you do not need those here. The /* … */ things. And put closing quote at the end of the style definition I.e, “>

    Your pretty much there just make sure it’s inside your loop and you will get a different number.

    Thanks guys. But still nothing. 🙁 Do I need to enclose anything in quotes or escape anything?

    sorry, i think i may be on to it.

    the value i needed was:

    transform:rotate(<?php echo $random_number;?>deg);

    with that added ‘deg’.. i tried to just add it,as you see, but its not showing up in the source code when rendered on the page. should i be using quotes?

    GOT IT! You guys were a big help!!! Thank you so much, have a great day. 😀

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘PHP variable as css value’ is closed to new replies.
Skip to toolbar