Home > database >  Opacity with PHP
Opacity with PHP

Time:12-29

Does it possible to hide a part of website like DIV or any tag with Opacity & Z-index in PHP Code instead of CSS

CSS Code :

#unwantedposition{
    opacity:0;
    z-index:9999;
    position:absolute;
    }

i am trying to rewrite my CSS code with PHP

PHP Code :

header("Content-type: text/css; charset: UTF-8");

   $opacity = "0";
   $z-index = "9999";
   $position = "absolute";

How can i fix this?. Please Help!!

CodePudding user response:

Try to achieve this with if statement example under the body the variable $hide set it on top of your html page

<body>
    <?php if($hide === true){ ?>    
    <div>this is my hidden div</div>
    <?php } ?>
    <div>some content</div>
</body>

CodePudding user response:

You could simply override that CSS class.

<?php
echo '<style>
    #unwantedposition{
    opacity:0;
    z-index:9999;
    position:absolute;
}
</style>';

That should be placed in your header tag, below your CSS file.

CodePudding user response:

You can conditionally show HTML tag:

<?php if ($isNeedToShow): ?>
  <div>...</div>
<?php endif ?>

CodePudding user response:

I don't understand what you mean. However, opacity and z-index are CSS properties. However, PHP doesn't have access to the DOM Element, it can only use a mix of HTML and CSS.

Then the question is, how to use PHP to mix HTML and CSS?

You can print <tag style="css-property: value;"></tag> Example :

<div style="opacity: 0; z-index: 9999; position: absolute"></div>

Did this answer help? If you have other questions you can add comments about your questions.

  • Related