Search code examples
phphtmlcssbackgroundfullscreen

Background image elements on top


I've been assigned the task to create a 404.php error page. I just started learning everything and this task is quite difficult. So far I have successuflly:

  • set up github + atom
  • clone the repository containing some code
  • set up MAMP + Wordpress and got the database working
  • trying to organize all the terms and trying to not confuse them

It's only been 4 days since I started from scratch with basically everything.

I managed to get this code into the 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(); ?>

And this is the 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%;
}

It looks like this on the localhost-page:

preview of 404

How can I make the other elements be on top of the background? I read several answers but I'm so confused right now that I need a specific hint for my case. Thanks in advance for helping!


Solution

  • So if i understand you correctly your background is overlapping right now? I think the property you are searching for is called the z-index.

    you probably need to do something like

        #bg{
          z-index: -1;
         }
    

    more info about z-index