使用PHP缓冲输出时min-height CSS属性不起作用ob_start()

问题描述:

实际上,我正在使用MVC结构处理PHP项目,其中包括DOCTYPE &在使用ob°开始的输出缓冲期间通过单个文件的HEAD标记()。使用PHP缓冲输出时min-height CSS属性不起作用ob_start()

问题出现在我要为可能页面容器声明一个最小高度属性时,为了将页脚粘贴到页面的底部。 ob_start() - ob_get_clean()使用似乎禁止浏览器及时访问这些属性,因此它们无法评估高度值。

这是我的index.php文件:

<?php 
include_once('global/init.php'); 
ob_start(); 
if(isset($_GET['module'])){ 
    $module = dirname(__FILE__).'/modules/'.htmlspecialchars($_GET['module']).'/'; 
    $action = (isset($_GET['action'])) ? htmlspecialchars($_GET['action']).'.php' : 'index.php'; 
    if(!file_exists($module.$action)){ 
     include('global/home.php'); 
    }else{ 
     include($module.$action); 
    } 
}else{ 
    include('global/home.php'); 
} 
$content = ob_get_clean(); 
include_once('global/header.php'); 
echo $content; 
include_once('global/footer.php'); 

header.php文件中包含的文档类型,和HTML的第一基础:

<html> 
<head> 
    <meta charset='UTF-8' /> 
    <title><?php echo "LiveSession".' '.DOMAIN_INFOS;?></title> 
    <meta name='description' content='<?php echo $_SESSION['currentDesc'];?>' /> 
    <meta name='keywords' content='<?php echo $_SESSION['currentKWds'];?>' /> 
    <link rel='stylesheet' media='screen and (max-width:480px)' href='css/smartphones.css' /> 
    <!-- TABLETS --> 
    <script type='text/javascript' src='scripts/jquery.1.7.js'></script> 
    <script type='text/javascript' src='scripts/poll_edit.js'></script> 
    <script type='text/javascript' src='scripts/smartphones.js'></script> 
</head> 
<body> 
    <div id='page'> 
     <div id='header'> 
      <h1><a href='index.php'>InteractivePollSession</a></h1> 
      <?php 
       if(is_connected_user()){ 
        echo "<span id='disconnector'><a href='index.php?module=members&amp;action=dscnx' title='disconnect'>Disconnect</a></span>"; 
       } 
      ?> 
     </div> 
     <div id='contentWrap'> 

页脚:

  </div> 
     <div id='footer'> 
      <span id='central-footer'>&copy; <a href='http://www.jsteitgen.com'>JSTeitgen</a></span> 
     </div> 
    </div> 
</body> 

A nd一个基本的CSS例:

body{height:100%;} 
#page{min-height:100%; position:relative;} 
#footer{position:absolute; bottom:0; width:100%;} 

是否有人知道如何解决这个使用ob_start()? 当然,所有其他的CSS规则做工精细,除了这...

感谢的

JS

+1

这似乎不太可能,服务器端代码会影响发送HTML/CSS的渲染。如果你删除输出缓冲,你能确认它是否有效? – jeroen

ob_start()是没有问题的。这个问题只是一个html/css问题。如果元素的父级具有固定高度,则只能使用百分比高度。

在你的情况,#pagebodybody的高度100%,所以你不能用百分比使用高度#page。但你可以尝试这个例子:

body{height: 1000px;} 
#page{min-height:100%; position:relative;} 
#footer{position:absolute; bottom:0; width:100%;} 

我认为问题是与CSS;您将body元素的高度设置为其父元素的100%,即html元素,该元素不一定具有100%的高度。

您应该能够使用解决你的问题:

html, body { 
    height: 100%; 
} 
+0

太棒了!完美的作品!非常感谢! – jst

+1

@ user1758625不客气。如果它适合您,请不要忘记接受答案(表决计数下的复选标记)。 – jeroen