【问题标题】:how to fix header and footer in php file如何修复php文件中的页眉和页脚
【发布时间】:2014-12-20 05:56:51
【问题描述】:

我正在使用 php 开发代码。我在另一个 php 文件 index.php 中导入两个文件(header.php 和 footer.php)。 现在我希望在水平滚动时应该修复 header.php 和 footer.php。你能建议我的代码吗?我正在使用以下代码

Header.php
 code here
footer.php
code here 

index.php

<?php include("header.php"); ?>
 welcome to index file 
 welcome to index file 
 welcome to index file 

<?php include("footer.php"); ?>

在这个文件 index.php 中,我希望在水平滚动时应该固定页眉和页脚,并且其他 css 也不应该受到干扰。

【问题讨论】:

  • 首先您需要了解 PHP 与它无关。它是 CSS 部分
  • 可以的话给个解决方案

标签: php css


【解决方案1】:

试试这个。

 <div id="header">
    <?PHP include_once('header.php');?>
    </div>
    <div id="wrap">
    welcome to index file
    </div>
    <div id="footer">
    <?PHP include_once('foo.php');?>
    </div>

css:

#header{position:fixed;top:0px;}
#footer{position:fixed;bottom:0px;}

header.php 
<div id ="header"></div><div id="content">
footer.php
</div><div id="footer"></div>

index.php
<?PHP include_once('header.php');?>
 content here.,
<?PHP include_once('footer.php');?>

【讨论】:

  • 页眉和页脚是固定的,但滚动一直工作到顶部和底部
【解决方案2】:

您的解决方案没问题。 只有我建议使用这样的东西:

<div id="header">
<?PHP include_once('header.php');?>
</div>
<div id="wrap">
here is my html content
</div>
<div id="footer">
<?PHP include_once('foo.php');?>
</div>

include_once 的使用是为了不重复某些文件的include 并通过良好的 css 获得出色的布局

【讨论】:

  • 你能给我推荐一下页眉、页脚和换行的css吗
  • @adeshsingh 我已经用 css 添加了一个答案。如果你有进一步的疑问,我可以帮助你.. :)
  • 滚动一直工作到顶部和底部,但我希望滚动应该从下面的页眉和页脚顶部开始
  • 查看latraiciondesargeras.x10.mx,我的一个网站,试试布局的html和css代码
【解决方案3】:

使用HTML5 并使用include_once

<header>
<?PHP include_once('header.php');?>
</header>
<div id="wrap">
here is my html content
</div>
<footer>
<?PHP include_once('foo.php');?>
</footer>

这里只是一个示例FIDDLE DEMO

html,body{
    margin:0;padding:0;
}
header{
    background:Green;
    height:50px;
}
footer{
    position:absolute;
    width:100%;
    bottom:0;
    background:Red;
    height:50px;
}

【讨论】:

    【解决方案4】:

    在你的 css 中,只需输入以下属性: position:fixed; 这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 2011-08-17
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多