Jump to content

[SOLVED] PHP & CSS Question?


Trium918

Recommended Posts

Is it possible to use php and css together.

 

Ok, I am trying to change the background of

the html page.

 

I can change the color, but how would I insert

an image?

<?php
// input for background color
$background = $_POST['background'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Background</title>
</head>

<?php echo "<body bgcolor=\"$background\">"; ?>

<form method="post" action="change_background.php">
<table border="1" align="center">
<tr>
<td align="center">
<input type="text" name="background" /><br  />
<input type="submit" name="submit" value="Change Background"/>
</td>
</tr>
</table>
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/55614-solved-php-css-question/
Share on other sites

I don't see any reference to CSS in there but yeah, using CSS on HTML that has been generated by PHP is well, just the same as using it in a normal HTML page. You can even make it dynamic or database drive.

 

As far as displaying an image...can you be more specific?

 

No, there is no CSS with in the code I provided. There

were no CSS needed. I am sure CSS will be needed to

change the background to an image.

 

For instance:

body{ background-image:url(image) }

 

I was wondering how can I use the code that I provided

in my first post to change the background so that an image

is displayed instead. Do you follow me?

 

Note: By using a form that is submitted to the php engine.

<?php

$bgimg = $_POST['bgimg'];
$bgcolor = $_POST['bgcolor'];
$tablebg = $_POST['tablebg'];

echo'
<style type="text/css">
  body {background-color: #'.$bgcolor.'; background-image: url(\''.$bgimg.'\');}
  table {background-color: #'.$tablebg.'; }
</style>';

?>

 

Something like that?

<?php

$bgimg = $_POST['bgimg'];
$bgcolor = $_POST['bgcolor'];
$tablebg = $_POST['tablebg'];

echo'
<style type="text/css">
  body {background-color: #'.$bgcolor.'; background-image: url(\''.$bgimg.'\');}
  table {background-color: #'.$tablebg.'; }
</style>';

?>

 

Something like that?

 

That is it. Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.