Solved

Gradient background scrolling in Firefox

Posted on 2013-01-10
3
559 Views
Last Modified: 2013-01-11
I'm having an issue with trying to get a CSS gradient background not to scroll in Firefox. It stays static in IE, but not in Firefox. Can someone please help?

Here's the example code:

<HTML>
      <HEAD>
            <style>
                  body
                  {
                        /*  establish the gradient for all pages  */
                         width: 100%;
                      height:100%;
                      margin: "0";
                        padding: "0";
                             
                        /* default background colour, for all layout engines that don't implement gradients */
                        background: #ffffff;
                      background-repeat: no-repeat;
                        color: #000000; /* text colour (black) */
                       
                        filter: progid:DXImageTransform.Microsoft.Gradient (startColorstr='#005595', endColorstr='#dddedf', gradientType='0'); /* IE based browsers */
                        background: -moz-linear-gradient(top, #006595 0%, #dddedf 100%); /* Mozilla (Firefox) based browsers */
                        background: -webkit-gradient(linear, left top, left bottom, from(#006595), to(#dddedf)); /* webkit based browsers */
                       
                        FONT-WEIGHT: normal;
                      FONT-SIZE: 9pt;
                      FONT-STYLE: normal;
                      FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
                  }

            </style>
      </HEAD>
      <BODY>
            <P>&nbsp;</P>
            <center>
                  <table width=50% height=2000 bgcolor=white>
                        <tr>
                              <td>&nbsp;</td>
                        </tr>
                  </table>
            </center>
            <P>&nbsp;</P>
      </BODY>
</HTML>

Cut that into a .htm file or open the attached file in both IE and Firefox and scroll to see what my issue is.

Thanks for your assistance.
gradient-test.html
0
Comment
Question by:LandyJ
3 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 250 total points
ID: 38766848
To prevent the background from scrolling, use the background-attachment property
background-attachment: fixed;

Open in new window

0
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 250 total points
ID: 38766974
Yeah, what @xmediaman said.

Interesting though that when you add a doctype and correct some of the other markup validation errors, the inconsistency between IE and FF disappears. In fact, the results become consistant across all browsers. Having a doctype and valid markup should be your starting point BEFORE implementing @xmediaman's suggestion. Here's your markup with corrections:
<!DOCTYPE html>
<html>

	<head>

		<style type="text/css">

			body

			{

				/*  establish the gradient for all pages  */

			 	width: 100%;

			    height:100%;

			    margin: "0"; 

				padding: "0";

					

				/* default background colour, for all layout engines that don't implement gradients */

				background: #ffffff;

			    background-repeat: no-repeat;

				color: #000000; /* text colour (black) */

				

				filter: progid:DXImageTransform.Microsoft.Gradient (startColorstr='#005595', endColorstr='#dddedf', gradientType='0'); /* IE based browsers */

				background: -moz-linear-gradient(top, #006595 0%, #dddedf 100%); /* Mozilla (Firefox) based browsers */

				background: -webkit-gradient(linear, left top, left bottom, from(#006595), to(#dddedf)); /* webkit based browsers */

				

				font-weight: normal;

			    font-size: 9pt;

			    font-style: normal;

			    font-family: Verdana, Arial, Helvetica, sans-serif

			}



		</style>

	</head>

	<body>

		<p>&nbsp;</p>

		<center>

			<table style="width:50%;height:2000px;background-color:#fff">

				<tr>

					<td>&nbsp;</td>

				</tr>

			</table>

		</center>

		<p>&nbsp;</p>

	</body>

</html>

Open in new window

0
 
LVL 7

Author Closing Comment

by:LandyJ
ID: 38767801
Thank you both. Both parts were missing from my code, so I will split the points.

Much appreciated.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question