Jump to content

Linking PHP in a stylesheet to main page


Wickham

Recommended Posts

This test code works well; it has variables to add up the widths of images and put the total width in a style in the head section style tags to create a width for a div.

 

If the style #pictures2d { width: <?php echo $totalwidth3 . "px"; ?>; height: 90px; } is put in a separate stylesheet the PHP won't connect with the variable in the main page. Is it possible to use a session to connect the stylesheet with the main page?

 

$image1_width = "435";
$image2_width = "90";
$totalwidth3 = 30+$image1_width+30+$image2_width+30+$image1_width+30+$image2_width+30+$image1_width+30;
?>  
<br />img { margin-right: 30px; padding: 0; }<br />img.first { margin-left: 30px; }<br />.pictures1 { width: 500px; border: 2px solid green; overflow: auto; height: 100px; }<br />#pictures2d { width: <?php echo $totalwidth3 . "px"; ?>; height: 90px; }<br />

 



alt="image 2"> alt="image 2">


 

I've tried putting all the php code with the variables in the stylesheet with the styles and renaming the stylesheet with a .php extension but it doesn't work.

 

EDIT:

 

I've answered my own question - I put all the php variables and styles in a separate file called style1.php (having added the style tags either side of the styles) so that the variables are in the same file as the style that uses one and used a PHP "include" in the main php file instead of a css file link.

 

It does get all the styles out of the main page, but in an include file instead of a css file.

Edited by Wickham
Link to comment
Share on other sites

I've seen another method which uses a link statement to add a css file with a 'php' file extension, and the php file includes a mime type suitable for the css contents.

If I get some free time tonight, I'll see if I can submit a demo.

Edited by jlhaslip
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...