使用CSS和PHP回显Div可见性?

I am trying to echo a CSS style in php. basically I want to make a Div visible. the Div's visibility is set to hidden in the css stylesheet and i need to make it visible in an else statement in php.

I am using this code:

<?php
} else {
    echo '<style type="text/css">
        #apDiv1 {
           visibility:visible;
        }
        </style>';
}
?>  

but that doesn't work! it doesn't make the Div visible. I tried it this way as a test and this way worked and it echo-ed hello world:

<?php
} else {
    echo 'hello world';
}
?>

so is there any other way to do this? am I doing anything wrong?

You can also try like

<?php
    } else {
 ?>
        <style type="text/css">
            #apDiv1 {
                visibility:visible;
            }
        </style>
<?php
    }
?>  

Or directly give the div style like

<?php
    } else {
?>
     <div id="appDiv1" style="visibility:visible"></div>
<?php }
?>

Even you can put !important if any other styles are applied on that div.

try visibility: visible !important;, or display: block.

You can use javascript instead of css

<script>
 document.getElementById('apDiv1').style.visibility = 'visible';
</script>

Do directly on the div:

<div id="apDiv1" <?php if(/* Your condition */){ /* Do something */ }else{ echo 'style="visibility:visible;"';} ?>></div>