Solved

Gradient background scrolling in Firefox

Posted on 2013-01-10
3
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Find out what you should include to make the best professional email signature for your organization.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

617 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