4

So first of all, I'm not a professional coder but I have some experience. I am trying to do a modern nice parallax website. So my problem is that the image in the background doesn't show in Firefox but it does in Chrome and I want it to work in both. Here is my code:

//No js yet
#welcome {
  font-family: 'Nunito', sans-serif;
  font-size: 80px;
  margin: 0px;
  color: #000;
  font-family: 'Slabo 27px', serif;
  background-color: #D5D5D5;
  height: 1000px;
  text-align: center;
  vertical-align: middle;
  line-height: 1000px;
  text-shadow: 0px 0px 10px grey;
  border-top: 1px solid black;
}

body {
  background-color: #000;
  font-family: 'Slabo 27px', serif;
  padding: 0px;
  margin: 0px;
}
#parallax {
   background-image: url("http://wp.widewallpapers.net/4k/cities/new-york/3840x2160/New-York-3840x2160-001.jpg");

    min-height: 100%; 
 margin: 0px;

    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}
<html>
<head>
  <link rel="stylesheet" href="style.css"/>
  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Slabo+27px" rel="stylesheet">
  <meta content="-1" http-equiv="expires"></meta>
  <meta content="text/html; charset=utf-8" http-equiv="content-type"></meta>
 </head>
<body>
<div id="parallax"></div>
<center><p align="center" id="welcome">Welcome To My Website!</p></center>
</body>
</html>

So if you copy all that and try it in chrome it works (for everyone I think), but it doesn't work in Firefox. HELP!

j08691
  • 204,283
  • 31
  • 260
  • 272
drstuggels
  • 122
  • 2
  • 12
  • On a side note the `
    ` tag has been deprecated (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center). There are plenty of things to help with centering. Here is a good resource: http://howtocenterincss.com/
    – zik Jan 26 '17 at 16:21
  • I have this question too. There's a CSS Only parallax demo site at: https://alligator.io/css/pure-css-parallax/ that works fine on every other browser except Firefox. – Ron B. Jan 29 '18 at 18:53

1 Answers1

1

Simple and easy fix is to add the height: 100% to the body{}

  body {
    background-color: #000;
    font-family: 'Slabo 27px', serif;
    padding: 0px;
    margin: 0px;
    height: 100%;
}

Additional options:

  1. Change min-height to height.

    #parallax {
       background-image: url("http://wp.widewallpapers.net/4k/cities/new-  york/3840x2160/New-York-3840x2160-001.jpg");
       height: 100%; 
       margin: 0px;
       background-attachment: fixed;
       background-position: center;
       background-repeat: no-repeat;
       background-size: cover;
    }
    
  2. Change min-height: 100% to min-height: 580px; (Or whatever pixel you want).

    #parallax {
       background-image: url("http://wp.widewallpapers.net/4k/cities/new-  york/3840x2160/New-York-3840x2160-001.jpg");
       min-height: 580px; //or whatever pixel you want... 
       margin: 0px;
       background-attachment: fixed;
       background-position: center;
       background-repeat: no-repeat;
       background-size: cover;
    }
    
Moses Davidowitz
  • 982
  • 11
  • 28