繁体   English   中英

如何更改三个不同div-s的主体背景

[英]How to change the body background for three different div-s

我有一个名为shtype_porosine.php的php文件,还有一个外部CSS文件style.css。 我用于登录网站的php文件,它具有三个不同的div标签。 对于第一个(div id =“ container_dyte”),主体背景颜色必须为白色,但对于其中包含的另外两个,颜色为('include / administrator_index_nsp.php'); 和include('include / login_forma.php'); 主体颜色必须为黑色。

我不确定a是否可以在同一个php文档中使用body标签3次,如果这样可以解决问题(使用body class =“”我在上一个问题“ how-to-css-if-else- to-change-body-background-color“),但如果不超过,那将是解决方案? 以下是php文件shtype_porosine.php的代码

谢谢

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>website</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <?php
        session_start();
        // this is for an administrator
        if(isset($_SESSION['auser'])){
    ?>
    <div id="container_dyte">
        <span>Something here...</span>
    </div>
    <?php
    }else{
        // these is for a user
        if(isset($_SESSION['p_user'])){
            include('include/administrator_index_nsp.php');
        }else{
            // this is the login form to apear if fails the adminstrator and the user
            include('include/login_forma.php');
        }
    }
    ?>
</body>
</html>

检查$_SESSION[ 'auser']是否已设置,如果已设置,请使主体为白色background-color

否则,将使主体具有黑色background-color

像这样:

<?php 
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>website</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<?php
if(isset($_SESSION['auser'])){ ?>
    <body style='background-color:white'>
<?php } else { ?>
    <body style='background-color:black'>
 <?php }

        if(isset($_SESSION['auser'])){
    ?>
    <div id="container_dyte">
        <span>Something here...</span>
    </div>
    <?php
    }else{
        // these is for a user
        if(isset($_SESSION['p_user'])){
            include('include/administrator_index_nsp.php');
        }else{
            // this is the login form to apear if fails the adminstrator and the user
            include('include/login_forma.php');
        }
    }
    ?>
</body>
</html>
<body class="<?= isset($_SESSION['auser']) ? 'white' : 'black';?>">
<body style="background-color:<?= isset($_SESSION['auser']) ? 'white' : 'black';?>">

您不必更改任何“主体”。 只需为每个div设置background-color css属性:

<div id="container_dyte" style="background-color:white">

在文件include / administrator_index_nsp.php中

<div style="background-color:black">

在文件include / login_forma.php中

<div style="background-color:black">

简单的方法:
为divs提供不同的ID名称并使用CSS。

的HTML

<div id="the_id">

的CSS

#the_id {
    background-color:white;
}

中方式:
使容器div具有专用ID或CLASS并设置CSS。

的CSS

#container div { 
    background-color: black;
}
#container:first-child { 
    background-color: red;
}
#container:last-child { 
    background-color: white;
}

艰辛的道路:
如果此页面有CSS专用符号,则可以按样式属性选择div编号。

body:nth-child(1) { background-color: black; };
body:nth-child(2) { background-color: red; };
body:nth-child(3) { background-color: white; };

如果css是其他页面的注释,请不要使用此答案。

为了解决此问题,请包括一个自定义的CSS,它将对<body>标签应用所需的背景颜色。 例如:

if (mode=='mode1')
{
   echo "<div id='div1'></div>";
   echo "<style type='text/css'> body { background-color:red } </style>";
}

if (mode=='mode2')
{
   echo "<div id='div2'></div>";
   echo "<style type='text/css'> body { background-color:yellow } </style>";
}

if (mode=='mode3')
{
   echo "<div id='div3'></div>";
   echo "<style type='text/css'> body { background-color:blue } </style>";
}

因此,根据显示的div,使用此逻辑,您可以设置主体的背景颜色

暂无
暂无

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

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