I have a php and html code and I have this
<?php
if (!$_SESSION['login']) {
$favicon = 'favicon.ico';
$logo = 'logo';
$bg = 'bg';
} elseif ($_SESSION['sex'] === 'Hombre') {
$favicon = 'faviconh.ico';
$logo = 'logoh';
$bg = 'bgh';
} else {
$favicon = 'faviconm.ico';
$logo = 'logom';
?>
<body>
etc
How I can put the bg var to put the background image with the if?
I try to put <?php echo 'background-image id="'.$bg.'"'; ?>> but doesn't work.
I have 3 Css so in the if when I put bg or bgh or bgm I am taking one background image or another or another.
Ant solution?
The css is
.bg {
backgroun-image: URL ('../img/bg.jpg');
}
.bgh {
backgroun-image: URL ('../img/bgh.jpg');
}
.bgm {
backgroun-image: URL ('../img/bgm.jpg');
}
Your code is fine, but result css is strange.
You can assign id to DOM like:
<div id="test"></div>
And in css part, you write something like:
#test {
background-image: url('path/to/image.jpg');
}
So, result:
<?php
$bg_id = 'bg_for_man';
?>
<style>
#bg_for_man {
background-image: url('/images/bg_for_man.jpg');
}
</style>
<body id="<?php print($bg_id); ?>">
<!-- Some html -->
</body>
you can it with this
$bg= '<style type="text/css">
body
{
background-image:url('image URL');
}
</style>';
echo $bg;
I finally put it correctly!
I do this
<body <?php echo 'id="'.$bg.'"' ?>
It works perfectly!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.