How do you add PHP to CSS?


Tags: php,html,css

Problem :

I was wondering if anyone can help. I am trying to add PHP code, which is retrieving an image from a database, into CSS.

I have the small section of CSS code on my example.php page and need to have different images for backgrounds depending on what variables were posted to the example.php page.

The terrible code that I have come up with is as follows

    <style>
    .par-surround {
        background-repeat: no-repeat;
        background-image:<?php <img src=<?=$subject['picture']?>border="0" width="740px"         height="auto"/> ?>  ; 
        background-position: center top;
     }
     </style>

I don't know if this can be done or if I have to do it a completely other way. Any help would be appreciated, thank you.



Solution :

The reasodin is correct. You just ned to have a valid PHP code:

<style>
    .par-surround {
        background-repeat: no-repeat;
        background-image: url(<?php echo $subject['picture'] ?>); 
        background-position: center top;
     }
 </style>

Also make sure $subject is defined and has a value, BEFORE you output the CSS code.


    CSS Howto..

    JQuery : How to disable mouse move vertically?

    How to calculate total size of all css,js and html pages separately uing shell script?

    How does Matt Haughey's blog insert rosettes in each post title? [closed]

    How do I convert a text to css hex value?

    How To Vertically Align Text On A Squarespace Button?

    CSS: how to make two sections at the same line?

    How to fix clickable background with Wordpress theme and CSS

    How can I add text right next to (to the right of) an ellipsis text overflow in CSS?

    How to select a child element in CSS?

    How do I prevent jQuery from resetting all my CSS?

    How to make multiple gradient work with CSS

    can anyone explain to me what does (content: “\f01a”; ) on css means? and how to use it?

    Ember css dosen't work + How to create two stylsheets

    How can I get a jquery css container to pop up letting the user know data was successfully entered?

    How do I achieve a fully working image scrolling effect like in this example?

    How to make HTML table cells expand horizontally beyond end of page?

    How to evenly distribute menu items with CSS when width and quantity is not known?

    How to add CSS class dynamically to html element

    How can I get my drop-down to not open unless the li is hovered?

    How to correct CSS formatting problem in Visual Studio

    how to show a portion of image like on 9gag.com

    How to get this functionality to work

    How do I apply CSS styles to Raphael.js objects using jQuery?

    boostrap menu active page dont show style

    Bootstrap progress bar with gradient color showing proportionally on active width

    How to embed Javascript in CSS?

    How to detect browser support for :after and :before

    How to figure out what is the right target to put in CSS

    How can I correctly center this div into its container? What is wrong?

    How can I remove the border around an image without a source?