Solved

Gradient background scrolling in Firefox

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bottom border change 5 15
How to create a textarea which saves text in HTML 8 37
"Pause" execution of javascript function for x miliseconds 2 26
Else condition 9 19
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

777 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