Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CSS如何防止html文件和包含的文件合并?_Php_Html_Css - Fatal编程技术网

Php CSS如何防止html文件和包含的文件合并?

Php CSS如何防止html文件和包含的文件合并?,php,html,css,Php,Html,Css,我的尝试和错误告诉我,当我(使用php)包含另一个php文件时,主体基本上是合并的我有一个CSS文件,它用“main”类影响主文件体。CSS文件也会对包含的文件体产生“nav”类的影响每个文件的两个主体似乎都受到针对每个类的两种样式的影响(即使每个主体标记上的类不同)

我的尝试和错误告诉我,当我(使用php)包含另一个php文件时,主体基本上是合并的

我有一个CSS文件,它用“main”类影响主文件体。CSS文件也会对包含的文件体产生“nav”类的影响

每个文件的两个主体似乎都受到针对每个类的两种样式的影响(即使每个主体标记上的类不同)<我弄错了吗?如果没有,有没有办法解决这个问题?谢谢

包括nav文件(包括css文件(我只显示与主体相关的代码):


如果您在两个包含文件中都声明了CSS,并且样式的作用域不特定于该页面上的元素,则可能会发生冲突。尤其是在设置基本标记(如body、span、div、table等)的样式时

在浏览器中编译页面时,所有内容都会被合并。长话短说。根据CSS在代码中的顺序,它可能会被覆盖。此外,根据样式的特殊性(真实单词),它可能会再次被覆盖

这可能会有所帮助

确保main和nav类不在这两个页面上,或者在这两个页面上都没有设置样式


我看到一些人做的另一件事是MVC(模型-视图-控制器)的新手调用部分页面是指它们在页面中包含HTML和BODY标记,在不需要时调用这些标记。

如果在这两个包含文件中都声明了CSS,并且样式的范围不特定于该页面上的元素,则可能会发生冲突。特别是在设置BODY等基本标记的样式时,跨度、分区、表格等

在浏览器中编译页面时,所有内容都会被合并。长话短说。根据CSS在代码中的顺序,它可能会被覆盖。此外,根据样式的特殊性(真实单词),它可能会再次被覆盖

这可能会有所帮助

确保main和nav类不在这两个页面上,或者在这两个页面上都没有设置样式


我看到一些人做的另一件事是MVC(model view controller)的新手,调用部分页面,他们在页面中包含HTML和BODY标记,这些标记在不需要时被调用。

不正确。首先,
include
require
是将一个脚本从一个文件注入到
\uuuuuuuuu文件中(主文件,在.htaccess/URL中打开的文件)例如:

file1.php

<?php
    $first_script_var = true;
    include 'file2.php';
?>
<html>
    <head>
        <title>Hello world</title>
        <script src="jquery.js"></script>
    </head>
    <body>
        <script>
            $(document).ready(function(){
                $.ajaxSetup({cache:false});
            });
            function load(){
                $("html").load("file2.php?string=" + document.getElementById("str").value); // $("html") is a selected, it basicly means we have selected the html tag. and the .load(); is a function from JQuery.
            }
        </script>
        <div>
            <input type="text" id="str" placeholder="Echo 'text'" />
            <br />
            <input type="button" onclick="load();" />
        </div>
    </body>
</html>

file2.php

<?php
    if(isset($first_script_var) && $first_script_var === true){
        echo 'True';
    }
?>
<head>
    <title>New title</title>
</head>
<body>
    <?php
        if(isset($_GET['string'])){ echo $_GET['string']; }
    ?>
</body>

现在,file1.php将如下所示:

<?php
    $first_script_var = true;
    include 'file2.php';
?>
<?php
    if(isset($first_script_var) && $first_script_var === true){
        echo 'True';
    }
?>
But if you would be using AJAX requests to the HTML DOM Element you would be requesting a file to the `html` tag it would load in the body tags.

但是,如果您要对HTMLDOM元素使用AJAX请求,那么您将向`HTML`标记请求一个文件,它将加载到body标记中。
示例:
< file1.php

<html>
    <head>
        <title>Hello world</title>
        <script src="jquery.js"></script>
    </head>
    <body>
        <script>
            $(document).ready(function(){
                $.ajaxSetup({cache:false});
            });
            function load(){
                $("html").load("file2.php?string=" + document.getElementById("str").value); // $("html") is a selected, it basicly means we have selected the html tag. and the .load(); is a function from JQuery.
            }
        </script>
        <div>
            <input type="text" id="str" placeholder="Echo 'text'" />
            <br />
            <input type="button" onclick="load();" />
        </div>
    </body>
</html>

你好,世界
$(文档).ready(函数(){
$.ajaxSetup({cache:false});
});
函数加载(){
$(“html”).load(“file2.php?string=“+document.getElementById(“str”).value”);//$(“html”)是选中的,这基本上意味着我们选择了html标记。而.load()是来自JQuery的函数。
}

file2.php

<?php
    if(isset($first_script_var) && $first_script_var === true){
        echo 'True';
    }
?>
<head>
    <title>New title</title>
</head>
<body>
    <?php
        if(isset($_GET['string'])){ echo $_GET['string']; }
    ?>
</body>

新标题

这将导致用新的头和新的体标记替换旧的头和体标记,记住!旧的javascript函数仍将被记住。

不正确。首先,
包括
要求
是将脚本从一个文件注入到
文件
(主文件,在.htaccess/URL中打开的文件)例如:

file1.php

<?php
    $first_script_var = true;
    include 'file2.php';
?>
<html>
    <head>
        <title>Hello world</title>
        <script src="jquery.js"></script>
    </head>
    <body>
        <script>
            $(document).ready(function(){
                $.ajaxSetup({cache:false});
            });
            function load(){
                $("html").load("file2.php?string=" + document.getElementById("str").value); // $("html") is a selected, it basicly means we have selected the html tag. and the .load(); is a function from JQuery.
            }
        </script>
        <div>
            <input type="text" id="str" placeholder="Echo 'text'" />
            <br />
            <input type="button" onclick="load();" />
        </div>
    </body>
</html>

file2.php

<?php
    if(isset($first_script_var) && $first_script_var === true){
        echo 'True';
    }
?>
<head>
    <title>New title</title>
</head>
<body>
    <?php
        if(isset($_GET['string'])){ echo $_GET['string']; }
    ?>
</body>

现在,file1.php将如下所示:

<?php
    $first_script_var = true;
    include 'file2.php';
?>
<?php
    if(isset($first_script_var) && $first_script_var === true){
        echo 'True';
    }
?>
But if you would be using AJAX requests to the HTML DOM Element you would be requesting a file to the `html` tag it would load in the body tags.

但是,如果您要对HTMLDOM元素使用AJAX请求,那么您将向`HTML`标记请求一个文件,它将加载到body标记中。
示例:
< file1.php

<html>
    <head>
        <title>Hello world</title>
        <script src="jquery.js"></script>
    </head>
    <body>
        <script>
            $(document).ready(function(){
                $.ajaxSetup({cache:false});
            });
            function load(){
                $("html").load("file2.php?string=" + document.getElementById("str").value); // $("html") is a selected, it basicly means we have selected the html tag. and the .load(); is a function from JQuery.
            }
        </script>
        <div>
            <input type="text" id="str" placeholder="Echo 'text'" />
            <br />
            <input type="button" onclick="load();" />
        </div>
    </body>
</html>

你好,世界
$(文档).ready(函数(){
$.ajaxSetup({cache:false});
});
函数加载(){
$(“html”).load(“file2.php?string=“+document.getElementById(“str”).value”);//$(“html”)是选中的,这基本上意味着我们选择了html标记。而.load()是来自JQuery的函数。
}

file2.php

<?php
    if(isset($first_script_var) && $first_script_var === true){
        echo 'True';
    }
?>
<head>
    <title>New title</title>
</head>
<body>
    <?php
        if(isset($_GET['string'])){ echo $_GET['string']; }
    ?>
</body>

新标题

这将导致用新的head和body标记替换旧的header和body标记,记住!旧的javascript函数仍然会被记住。

真的不知道“当我包含另一个php文件时,主体基本上合并”是什么意思吗。当您使用
include
require
时,基本上是在执行点将一个PHP文件的脚本注入另一个PHP文件。任何
脚本都会被合并,任何输出都会被缓冲。可能最好包含css文件,因为您可能在这两个实例中都包含了一些内容。@Phil I解释了发生的情况ve.由于某些原因,每个主体的css都会影响另一个主体。即使我在每个文件中都以主体的唯一类为目标。我只在所包含的文件中包含css文件。一个(有效)html页面不能有多个
标记。我真的不确定“当我包含另一个php文件时,主体基本上合并”是什么意思。当您使用
include
require
时,基本上是在执行点将一个PHP文件的脚本注入另一个PHP文件。任何
脚本都会被合并,任何输出都会被缓冲。可能最好包含css文件,因为您可能在这两个实例中都包含了一些内容。@Phil I解释了发生的情况ve.ea的css