0

Hello all. I am working with some code like this.

echo"<div style='background-image: url(boxshadow2small.jpg);text-align:center; height: 266px; width: 225px; '></div>";

I wanted to be able to control the size of this div with php conditions. I thaught i could do it like this, but its not working.

$someVariable = 200;

echo"<div style='background-image: url(boxshadow2small.jpg);text-align:center; height: $someVariable px; width: 225px; '></div>";

$someVariable is the kind of information i would alter with the use of php control statements. I really would like to get this kind of action working. Does anyone know of something like this being possable? thanks. I guess it would be called dynamic div creation. i duno ,thanks.

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by jonnyboy12
0

I don't think your code is wrong. It works here and it should work. Try these alternatives, just in case.

echo "<div style='background-image: url(boxshadow2small.jpg);text-align:center; height: {$someVariable}px; width: 225px; '></div>"; 
//OR
echo "<div style='background-image: url(boxshadow2small.jpg);border:1px solid #333; text-align:center; height: ".$someVariable."px; width: 225px; '></div>";

Edited by kekkaishi: n/a

0

Your code is OK. I have been using this approach quite often (e.g. conditionally applying a background colour to a table). What makes you think the code does not work? Maybe the change just isn't visible. Try changing some other attributes to see whether there is any effect. Try:

$bgrPic1 = 'boxshadow1small.jpg';
$bgrPic2 = 'boxshadow2small.jpg';

echo"<div style='background-image: url($bgrPic1);text-align:center; height: 266px; width: 225px; '></div>";
echo"<div style='background-image: url($bgrPic2);text-align:center; height: 266px; width: 225px; '></div>";

Edited by broj1: Typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.