2017-01-03 101 views
1

我已經分配了任務來創建一個404.php的錯誤頁面。我剛開始學習一切,這項任務相當困難。到目前爲止,我有successuflly:頂部的背景圖像元素

  • 設立的github +原子
  • 克隆包含一些代碼
  • 庫建立甲基苯丙胺+ WordPress的,並得到了數據庫工作
  • 試圖組織所有的條款,並試圖不要混淆他們

這只是連續4日以來,我從頭開始基本上一切。

我設法得到這個代碼進入404.php:

> <?php 
/** 
* The template for displaying 404 pages (Not Found). 
**/ 

get_header(); ?> 
<div id="bg"> 
    <img src="<?php echo get_bloginfo('template_directory'); ?> \img\Free-Chalkboard-Backgrounds.jpg" alt="background"> 
</div> 
<header class="entry-header"> 
<center> 
<h1 class="entry-title">404 - Not found</h1> 
</center> 
</header> 

<article id="post-0" class="post error404 no-results not-found"> 
<div class="entry-content"> 
<p><big>404 - Die Seite konnte nicht gefunden werden.</big></p> 
      <?php get_search_form(); ?> 
      <!-- <img class="img-responsive" src="<?php echo $logoUrl; ?>" alt="Logo - <?php echo get_bloginfo('name'); ?>"> --> 
      <center><img src="<?php echo get_bloginfo('template_directory'); ?> \img\internet-error-404-file-not-found.jpg" alt="404 not-found" /> 
      </center> 
     </div> 
<!-- .entry-content --> 
    </article> 
<!-- #post-0 --> 
<footer> 


    <ul class="list-inline Impressum"> 
    <li> <a href="https://www.th-nuernberg.de/seitenbaum/impressum/page.html" target="blank"> 
     <alt=>Impressum</a> </li> 
     <li> | 
     </li> 
    <li> <a href="https://www.th-nuernberg.de/institutionen/hochschulkommunikation/ohm-shop/agb/page.html" target="blank"> 
     <alt=>AGB</a> </li> 
     <li> | 
     </li> 
    <li> <a href="https://www.th-nuernberg.de/institutionen/language-center/ueber-uns/page.html" target="blank"> 
     <alt=>Über uns</a> </li> 
    </ul> 


</footer> 

<?php get_footer(); ?> 

這是CSS:

#bg { 
    position: fixed; 
    top: -64%; 
    left: -55%; 
    width: 200%; 
    height: 200%; 
} 
#bg img { 
    position: absolute; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    margin: auto; 
    min-width: 55%; 
    min-height: 55%; 
} 

它看起來像這樣的本地主機的網頁上:

preview of 404

我怎樣才能使其他元素在背景之上?我讀了幾個答案,但我現在很困惑,我需要一個具體的提示,以我的情況。 在此先感謝您的幫助!

+0

只是在你的CSS背景添加這種風格「背景位置:頂部中心;」作爲一個附註, –

+1

:'

'和''標籤已被棄用。你不應該使用它們。 – chillwalker

+0

感謝您的提示,我要用什麼來代替? –

回答

2

所以,如果我理解正確,你的背景,現在的重疊? 我認爲你正在尋找的財產被稱爲Z指數。

你可能需要做一些像

#bg{ 
     z-index: -1; 
    } 

more info about z-index

+0

謝謝,我用#bg替換了.bg,因爲它有'id =「bg」'所以我需要用#調用它?在我向HKs代碼添加之後,它似乎奏效了。 –

+0

哎呀!這是正確的,我忘了他使用ID BG而不是班級BG ..感謝您的編輯! –

0

嘗試一次...

<?php 
/** 
* The template for displaying 404 pages (Not Found). 
**/ 

get_header(); ?> 
<div id="bg"> 
    <img src="<?php echo get_bloginfo('template_directory'); ?> \img\Free-Chalkboard-Backgrounds.jpg" alt="background"> 
</div> 
<header class="entry-header"> 
<center> 
<h1 class="entry-title">404 - Not found</h1> 
</center> 
</header> 

<article id="post-0" class="post error404 no-results not-found"> 
<div class="entry-content"> 
<p><big>404 - Die Seite konnte nicht gefunden werden.</big></p> 
      <?php get_search_form(); ?> 
      <!-- <img class="img-responsive" src="<?php echo $logoUrl; ?>" alt="Logo - <?php echo get_bloginfo('name'); ?>"> --> 
      <center><img src="<?php echo get_bloginfo('template_directory'); ?> \img\internet-error-404-file-not-found.jpg" alt="404 not-found" /> 
      </center> 
     </div> 
<!-- .entry-content --> 
    </article> 
<!-- #post-0 --> 
<footer> 


    <ul class="list-inline Impressum"> 
    <li> <a href="https://www.th-nuernberg.de/seitenbaum/impressum/page.html" target="blank"> 
     <alt=>Impressum</a> </li> 
     <li> | 
     </li> 
    <li> <a href="https://www.th-nuernberg.de/institutionen/hochschulkommunikation/ohm-shop/agb/page.html" target="blank"> 
     <alt=>AGB</a> </li> 
     <li> | 
     </li> 
    <li> <a href="https://www.th-nuernberg.de/institutionen/language-center/ueber-uns/page.html" target="blank"> 
     <alt=>Über uns</a> </li> 
    </ul> 


</footer> 

<?php get_footer(); ?> 

CSS

.bg-img { 
    background-position: right 45px bottom; 
} 

#bg { 
    position: fixed; 
    top: -64%; 
background-position: top center; 
    left: -55%; 
    width: 200%; 
    height: 200%; 
} 
#bg img { 
    position: absolute; 
    top: 0; 
background-position: top center; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    margin: auto; 
    min-width: 55%; 
    min-height: 55%; 
} 
+0

感謝您的快速回復,我複製粘貼您的代碼,但結果沒有改變。當我重新加載404頁面時,我可以很快看到元素彈出,但它們立即消失。它仍然是相同的背景圖像填充整個屏幕,其他一切都在它後面。我發現這個問題與我的猜測類似,但我不知道如何或在何處插入此代碼? http://stackoverflow.com/questions/40508355/background-image-and-elements-on-it –

+0

你只需要在背景div中添加樣式 –

+0

你試過了嗎? –