EnergyLynx EnergyLynx
EnergyLynx EnergyLynx

Reputation: 115

echo Div visibility using CSS and PHP?

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?

Upvotes: 0

Views: 8776

Answers (4)

CIRCLE
CIRCLE

Reputation: 4879

Do directly on the div:

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

Upvotes: 0

NavaStha
NavaStha

Reputation: 96

You can use javascript instead of css

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

Upvotes: 1

NDM
NDM

Reputation: 6830

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

Upvotes: 3

GautamD31
GautamD31

Reputation: 28763

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.

Upvotes: 3

Related Questions