2013-01-23 38 views
0

實際上,我正在使用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

回答

0

ob_start()是沒有問題的。這個問題只是一個html/css問題。如果元素的父級具有固定高度,則只能使用百分比高度。

在你的情況,#pagebodybody的高度100%,所以你不能用百分比使用高度#page。但你可以嘗試這個例子:

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

我認爲問題是與CSS;您將body元素的高度設置爲其父元素的100%,即html元素,該元素不一定具有100%的高度。

您應該能夠使用解決你的問題:

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

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

+1

@ user1758625不客氣。如果它適合您,請不要忘記接受答案(表決計數下的複選標記)。 – jeroen