Solved

Gradient background scrolling in Firefox

Posted on 2013-01-10
3
556 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 21

Accepted Solution

by:
Kim Walker earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you both. Both parts were missing from my code, so I will split the points.

Much appreciated.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now