I usually try to avoid using PHP procedures inside CSS; especially embedded CSS (CSS that is on the same page).
I would save your CSS in my own CSS file and use the PHP condition to add the hide class to the DIV -OR- do not drop the DIV at all.
<link rel="stylesheet" type="text/css" href="style.css" />
<body>
<div id="content" <?php if(conditional) : ?>class="hide"<?php endif;?>>
Foo bar
</div>
</body>
or alternatively
<?php $class = (conditional) ? "hide" : ""; ?>
<link rel="stylesheet" type="text/css" href="style.css" />
<body>
<div id="content" class="<?=$class?>">
Foo bar
</div>
</body>
or
<link rel="stylesheet" type="text/css" href="style.css" />
<body>
<?php if (conditional) : ?>
<div id="content">
Foo bar
</div>
<?php endif; ?>
</body>
Many times a div must be displayed so that it can be re-rendered using JavaScript (e.g. carousels, sliders, etc.).
source
share