0

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?

6
  • 2
    Could you show us the HTML for that div? Commented Sep 23, 2013 at 12:03
  • There just isn't enough information in you question for us to know what it is exactly that you want to do. Commented Sep 23, 2013 at 12:05
  • 1
    why the downvote? I don't understand why some people are just waiting for someone to post a question here and just downvote the question without any reason! Commented Sep 23, 2013 at 12:06
  • @EnergyLynxEnergyLynx: Can we see your HTML? Normal case the above should have worked. Maybe there is some other problem somewhere else. Commented Sep 23, 2013 at 12:09
  • 2
    @EnergyLynxEnergyLynx: And to answer the other question. Do not bother about a down-vote. If the question has enough detail and shows that analysis was done prior to asking the question, it will eventually get into the positive. I am not saying that asking for reason is wrong though. Commented Sep 23, 2013 at 12:11

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

I did try that before i posted this question and that didn't work either.
1

You can use javascript instead of css

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

Comments

0

Do directly on the div:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.