doutuo7609 2015-01-12 17:19
浏览 54

PHP包含两个css文件[关闭]

I have an issue where I have one page that has it's own css file and I am including, using

include $_SERVER[DOCUMENT_ROOT].'path/file.php';

to include a banner which has it's own css file but they share similar classes, is there a way I can stop the two css files from bleeding into each other?

Edit:

Ok so to elaborate on my question because I know that it is very vague, what I am trying to do is to get the page the user visits, this one here:

<?php include $_SERVER['DOCUMENT_ROOT'].'/aaron/portfolio/banner.php'; ?><!doctype html><html>
    <head>
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
        <meta content="utf-8" http-equiv="encoding">
        <link rel="shortcut icon" type="image/ico" href="/wyeweb/img/wyelearn.ico"/>
        <link rel="stylesheet" type="text/css" href="/wyeweb/css/bootstrip.css" />
        <link rel="stylesheet" type="text/css" href="/wyeweb/css/otherCss.css" />
        <script src="/wyeweb/js/jquery.js" type="text/javascript"></script>
        <script type="text/javascript" src="/wyeweb/js/bootstrip.js"></script>
        <script src="/wyeweb/js/CSS3_Media.js" type="text/javascript"></script>
        <script src="/wyeweb/js/respond_min.js" type="text/javascript"></script>
        <title>
             | Home
        </title>
    </head>
    <body>
        <div class="container col-md-offset-3">
            <div class="container col-md-8"><a href="/wyeweb/index.php"><img class="logo-size" src="img/wyeLogo.jpg" alt="Logo"></a></div><!--Logo-->
            <div class="col-md-4 address">
        <a href="http://www.facebook.com/...">
          <img src="/wyeweb/img/face.jpg" alt="facebook">
        </a>
        <a href="http://www.twitter.com/...">
          <img src="/wyeweb/img/twit.jpg" alt="twitter">
        </a>
        <a href="http://www.linkedin.com/company/...">
          <img src="/wyeweb/img/link.jpg" alt="linkedin">
        </a>
        <br/><br/>
        <a href="...">
          ...<br/>...<br/>...<br/>...
        </a>
      </div><!--address with link to gmaps-->
        </div>...

To call the CSS files at the top but the page ignores these files and calls all classes from the CSS files at the top of the included page here:

<?php
      $output = 'AN Web Design | %title%';
      
      if($_SERVER['REQUEST_URI'] == '/aaron/portfolio/wyeweb/')
      {
        $output = str_replace('%title%', 'Wyelearn', $output);
      }
      elseif($_SERVER['REQUEST_URI'] == '/aaron/portfolio/portal/')
      {
        $output = str_replace('%title%', 'Concept', $output);
      }
      //elseif($_SERVER['REQUEST_URI'] == '/aaron/prtf.php')
      //{
      //  $output = str_replace('%title%', 'Portfolio', $output);
      //}
      else
      {
        $output = str_replace('%title%', 'View', $output);
      }
    ?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html>
    <head>
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
        <meta content="utf-8" http-equiv="encoding">
        <title><?php echo $output ?></title>
        <link rel="shortcut icon" type="image/png" href="/aaron/IMG/r1ico.jpg" />
        <link rel="stylesheet" type="text/css" href="/aaron/css/bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="/aaron/css/strap_overwrite.css" />
        <script src="/aaron/js/jquery.js"></script>
        <script src="/aaron/js/bootstrap.js" type="text/javascript"></script>
        <script src="/aaron/js/CSS3_Media.js" type="text/javascript"></script>
        <script src="/aaron/js/respond_min.js" type="text/javascript"></script>
        
    </head>
    <body>
        <div class="banner">
            <div>
                <nav class="navbar navbar-default" role="navigation">
                    <div>
                        <div class=" container">
                        <div class="navbar-header">
                            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                                <span class="sr-only">Toggle Nav Bar</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                
                            </button>
                            <a class="navbar-brand" href="index.php">AN Web Design</a>...

So what I want to do is get the page the user visits to ignore the called files at the top of the above page and only use the ones from the main page. Is there a way to do this?

</div>
  • 写回答

1条回答 默认 最新

  • doubu1853 2015-01-12 17:21
    关注

    Maybe you can wrap the banner.php file in a div

    <div class="thebanner"></div>
    

    And then add .thebanner in front of every similar class like so:

    .thebanner .title
     {
       ...
     }
    
    .thebanner .content
     {
       ...
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)