WordPress.org

Ready to get started?Download WordPress

Forums

PHP variable as css value (10 posts)

  1. dtek516
    Member
    Posted 1 year ago #

    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.

  2. dtek516
    Member
    Posted 1 year ago #

    by the way:
    i tried the method here, to no avail.

    http://css-tricks.com/css-variables-with-php/

  3. mojowill
    Member
    Posted 1 year ago #

    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.

  4. dtek516
    Member
    Posted 1 year ago #

    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?

  5. dtek516
    Member
    Posted 1 year ago #

    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. :D

  6. Gagan Goraya
    Member
    Posted 1 year ago #

    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, ">

  7. mojowill
    Member
    Posted 1 year ago #

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

  8. dtek516
    Member
    Posted 1 year ago #

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

  9. dtek516
    Member
    Posted 1 year ago #

    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?

  10. dtek516
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.