简体   繁体   English

使用PHP更改CSS

[英]changing css using php

Im trying to do a link from one page to another, on the link itself I send a variable that the receiving page gets with php, then I need the php to echo out js to change the css display on two divs, changing the div whose default css is block to that of hidden and a second div whose default css is none to that of block. 我试图做一个从一页到另一页的链接,在链接本身上,我发送了一个接收页面通过php获取的变量,然后我需要php回显js来更改两个div上的css显示,更改其div默认的css是对hidden的阻止,而第二个div的默认css与对block的默默无关。 I have suucesfully passed the variable within the url, and the js to change the second div to block works, however the 1st div css doesnt seem to change to none as the div still shows 我已经成功地在url中传递了变量,并且js将第二个div更改为阻止工作,但是第一个div的css似乎并没有改变,因为div仍然显示

PHP code PHP代码

if (isset($_GET['display'])) {

    if(!isset($_GET['yes'])) {

        echo '<style type="text/css">

              #slideshow {
                  display: none;
              }
              </style>';

        echo '<style type="text/css">

              #aboutus {
                  display: block;
              }
              </style>';
    }

}else{



};

Can anyone help me resolve this please 谁能帮我解决这个问题

Are you sure you don't mean this: 您确定不是这个意思吗?

if($_GET['display'] == 'yes') {

I would pass an integer value rather than 'yes' and 'no'. 我将传递一个整数值,而不是“ yes”和“ no”。

Then do it this way: 然后以这种方式进行:

<?php
ob_start("ob_gzhandler");
header('Content-Type: text/html; charset=utf-8');
header('Connection: Keep-Alive');
header('Keep-Alive: timeout=5, max=100');
header('Cache-Control: max-age=84600');
header('Vary: Accept-Encoding');
echo <<<EOT
<!DOCTYPE html>
<html lang="en"><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>page Title</title>
<style type="text/css">
.hide{display:none;}
</style>
</head><body><div id="page">

EOT;
ob_flush();

$display = inval($_GET['display']); 

$aboutclass = array(' class="hide" ','');
$slideclass = array('',' class="hide" ');

echo '<div id="aboutus" ' . $aboutclass [$display] . '>'
echo '<div id="slideshow" ' . $slideclass [$display] . '>'


echo '</div></body></html>';
ob_end_flush();

I found a solution, using the following code 我使用以下代码找到了解决方案

PHP PHP

if(isset($_GET['display']) != 'yes'){

$slider = 'block';


$aboutus = 'none';


}else{

$slider = 'none';

$aboutus = 'block';

}

Then I removed the display stying from the external stylesheet for the .slideShow and .aboutus and added inline styles just for the display within the head section of the html code as follows 然后,我从.slideShow和.aboutus的外部样式表中删除了显示样式,并为html代码的头部部分中的显示添加了内联样式,如下所示

<style type="text/css">

.sliderWrapper {
    display: <?php echo $slider; ?>
}

.aboutUs {
    display: <?php echo $aboutus; ?>

    };
</style>

Then it worked as required. 然后按要求工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM