Firefox background-position problem solved

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 120
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Firefox background-position problem solved

 
0
  #1
Mar 11th, 2008
I had a background image for one of the container divs in my page. I positioned it to a specific pixel using its style properties. It worked fine in the internet explorer but was located to a wrong position when displayed by firefox. So i wrote the following code to get around this problem, it worked.

  1. <div id="container" style="background-image: url(images/navigationMenut/left-tile.jpg);background-repeat: no-repeat; background-position: left 109px;">
  2. </div>

I insert the following script right after the container div.

  1. <script>
  2. // checks the browser type to see if it is firefox
  3. if (navigator.appName.indexOf('Netscape') != -1)
  4. {
  5. // changes the position accordingly
  6. document.getElementById('container').style.backgroundPosition
  7. = "left 107px";
  8. }
  9. </script>

This approach can be applied to all style conflicts between firefox and internet explorer.
Last edited by peter_budo; Mar 12th, 2008 at 1:46 pm. Reason: Keep It Organized - please use [code] tags
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 1
Reputation: John Rosegort is an unknown quantity at this point 
Solved Threads: 1
John Rosegort John Rosegort is offline Offline
Newbie Poster

Re: Firefox background-position problem solved

 
0
  #2
Apr 30th, 2009
Originally Posted by serkan sendur View Post
I had a background image for one of the container divs in my page. I positioned it to a specific pixel using its style properties. It worked fine in the internet explorer but was located to a wrong position when displayed by firefox. So i wrote the following code to get around this problem, it worked.

  1. <div id="container" style="background-image: url(images/navigationMenut/left-tile.jpg);background-repeat: no-repeat; background-position: left 109px;">
  2. </div>

I insert the following script right after the container div.

  1. <script>
  2. // checks the browser type to see if it is firefox
  3. if (navigator.appName.indexOf('Netscape') != -1)
  4. {
  5. // changes the position accordingly
  6. document.getElementById('container').style.backgroundPosition
  7. = "left 107px";
  8. }
  9. </script>

This approach can be applied to all style conflicts between firefox and internet explorer.
You should use the above but instead use document.getElementById('container').style.backgroundPosition=100% 50%
This works for Firefox and Internet Explorer did not check it on Safari or any of the other browsers
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: TempName6234572 is an unknown quantity at this point 
Solved Threads: 0
TempName6234572 TempName6234572 is offline Offline
Newbie Poster

Another solution

 
0
  #3
Oct 20th, 2009
Y-positioning with a "bottom"-value is still a problem in Firefox. The solution is to first set height = "100%"! Example...

  1. <script type="text/javascript">
  2. //...For example you set the background in fram x to bottom-right...
  3. bFn = getElementsByAttribute(top.frames[x].document,"body","background")[0];
  4. bFn.style.margin = "0";
  5. bFn.style.padding = "0";
  6. bFn.style.width = "100%";
  7. bFn.style.height = "100%"; // <<< important
  8. bFn.style.backgroundRepeat = "no-repeat";
  9. bFn.style.backgroundPosition = "right bottom"; //x y
  10. </script>
Last edited by TempName6234572; Oct 20th, 2009 at 3:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: TempName6234572 is an unknown quantity at this point 
Solved Threads: 0
TempName6234572 TempName6234572 is offline Offline
Newbie Poster
 
0
  #4
Oct 20th, 2009
CHANGE background TO bgcolor !!! I missed to test the last change I made
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC