2014-05-21 22 views
0

出於某種原因,我加載雖然我的帖子的圖像不加載居中。它加載在頁面的左上角,就像頁面上沒有CSS一樣。我已經翻了幾遍代碼,但我無法弄清楚它有什麼問題。圖像不是中心在頁面

下面的代碼是我的index.php

<?php $i = urlencode($_GET['i']); 

$image = str_replace("%2F", "/", $i); 


?> 
<head> 
<title>RizzelDazz Images</title> 

<Style type=css> 
* 
{ 
    padding: 0; 
    margin: 0; 
} 
#over 
{ 
    position:absolute; 
    width:100%; 
    height:100%; 
    text-align: center; /*handles the horizontal centering*/ 
} 
/*handles the vertical centering*/ 
.Centerer 
{ 
    display: inline-block; 
    height: 100%; 
    vertical-align: middle; 
} 
.Centered 
{ 
    display: inline-block; 
    vertical-align: middle; 
} 
</style> 
</head> 

<body> 

<div id="over"> 
    <span class="Centerer"> 
    <?php if($i=="") { echo ""; } else { echo"<img src='/../images" . $image . ".jpg'/>"; } ?> 
    </span> 
</div> 


</body> 
+0

而不是'.Centerer {...}''嘗試跨度.Centerer {...}' –

+0

對我的作品罰款:http://jsfiddle.net/K7y8f/ – APAD1

+0

@弗雷德-II-這似乎並沒有工作 – user3546563

回答

0

我想這是因爲你需要添加

<style type="text/css"> 

,而不是僅僅

<style type="css"> 

它仍然可以工作在jsfiddle,因爲不需要陳述樣式類型。希望這有助於:)

3

如果您發佈的代碼是你index.php文件的全部內容,你有幾個問題:

  1. 你沒有doctype。在index.php文件的頂部包含<!DOCTYPE html>
  2. 您有沒有<html></html>標籤。文檔中的所有內容都應該放在<html></html>標籤內。
  3. 你的開頭<style>標記是錯誤的。你有它作爲<Style type=css>;它應該是:

    <style type="text/css">(沒有大寫字母,引號text/css

下面是這些變化的代碼 - 他們將最有可能解決您的問題。

<!DOCTYPE html> 
<html> 
<?php $i = urlencode($_GET['i']); 
    $image = str_replace("%2F", "/", $i); 
?> 
<head> 
<title>RizzelDazz Images</title> 
<style type="text/css"> 
* { 
    padding: 0; 
    margin: 0; 
} 
#over { 
    position:absolute; 
    width:100%; 
    height:100%; 
    text-align: center; /*handles the horizontal centering*/ 
} 
/*handles the vertical centering*/ 
.Centerer { 
    display: inline-block; 
    height: 100%; 
    vertical-align: middle; 
} 
.Centered { 
    display: inline-block; 
    vertical-align: middle; 
} 
</style> 
</head> 

<body> 
<div id="over"> 
    <span class="Centerer"> 
    <?php if($i=="") { echo ""; } else { echo"<img src='/../images" . $image . ".jpg'/>"; } ?> 
    </span> 
</div> 
</body> 
</html>