Solved

What's wrong with my code? DIV shits to the right when viewed in Internet Explorer 8 compatibility view.

Posted on 2010-09-03
4
438 Views
Last Modified: 2012-05-10
Hi,

I'm using a DIV called 'container' as a holder so that pages always display centred in any browser.
I'm trying to include a nested DIV with a useful vertical scrolling marquee replacement script.
I'm happy that the script works under ie 8, firefox, opera and chrome. However in internet explorer 8 compatibility view, and presumably ie7 and ie6, the nested DIV shifts to the centre of the page.

It's supposed to be on the left.

I'm guessing this has something to do with the way I'm centreing my page?

Can anyone help fix this so it displays correctly (on the left) in older browsers and in ie8.

Thanks.

Code included - if you test it in ie8, switch between compatibility view to see what I mean.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<STYLE type="text/css">

       html, BODY { background: black;
       text-align:center;
       padding:0;
       margin:0;
       height: 100%;
}
    </STYLE>
<style type="text/css">


#container
{
	position:relative;
	padding:0;
	margin-left: auto;
	margin-right: auto;
	width: 50em;
	text-align: center;
	min-height: 100%;
	background: white;
} 

</STYLE>

<style type="text/css">
#marquee_replacement{
 border:1px solid #000;
 width:200px;
 height:150px;
 overflow:hidden;
}
#marquee_replacement p.spacer{
 height:150px;
}
</style>


<script type="text/javascript">
// <!--
var speed = 1; // change scroll speed with this value
/**
 * Initialize the marquee, and start the marquee by calling the marquee function.
 */
function init(){
  var el = document.getElementById("marquee_replacement");
  el.style.overflow = 'hidden';
  scrollFromBottom();
}
 
var go = 0;
var timeout = '';
/**
 * This is where the scroll action happens.
 * Recursive method until stopped.
 */
function scrollFromBottom(){
  clearTimeout(timeout);
  var el = document.getElementById("marquee_replacement");
  if(el.scrollTop >= el.scrollHeight-150){
    el.scrollTop = 0;
  };
  el.scrollTop = el.scrollTop + speed;
  if(go == 0){
    timeout = setTimeout("scrollFromBottom()",50);
  };
}
 
/**
 * Set the stop variable to be true (will stop the marquee at the next pass).
 */
function stop(){
  go = 1;
}
 
/**
 * Set the stop variable to be false and call the marquee function.
 */
function startit(){
  go = 0;
  scrollFromBottom();
}
// -->
</script>




</head>



<BODY onload="startit()">

    
<div id="container">

<div id="marquee_replacement" onmouseout="startit();" onmouseover="stop();">
<p class="spacer"></p>
<p>line 1</p>
<p>line 2</p>
<p>line 3</p>
<p>line 4</p>
<p class="spacer"></p>
</div>




</div>

</body>
</html>

Open in new window

0
Comment
Question by:rapidpictures
[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
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Animasu
ID: 33596468
Try centring it like this:

#container
{
      position:absolute;
      padding:0;
      left:-25em;
      margin-left: 50%;
      width: 50em;
      text-align: center;
      min-height: 100%;
      background: white;
}

It also works with position:relative i think...
Also each CSS element dosn't have to be in its own container. i.e: <style type="text/css"> </style>


Hope this helps

- Animasu
0
 
LVL 3

Expert Comment

by:vimalraja
ID: 33596617
Try changing "text-align:center" of the #container to "text:align:left;"...
#container
{
	position:relative;
	padding:0;
	margin-left: auto;
	margin-right: auto;
	width: 50em;
	text-align: left;
	min-height: 100%;
	background: white;
}

Open in new window

0
 

Accepted Solution

by:
rapidpictures earned 0 total points
ID: 33596719
Sorry that still shifts to the right.
I have fixed it using another div (called 'holdall') to nest the marquee script within (set absolute position).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<STYLE type="text/css">

       html, BODY { background: black;
       text-align:center;
       padding:0;
       margin:0;
       height: 100%;
       overflow:auto;
}
    </STYLE>
<style type="text/css">


#container
{
	position:relative;
	padding:0;
	margin-left: auto;
	margin-right: auto;
	width: 50em;
	text-align: center;
	min-height: 100%;
	background: white;
} 

#holdall
{
	position:absolute;
	left: 0px;
	top: 0px;
}

</STYLE>

<style type="text/css">
#marquee_replacement{
 border:0px;
 width:200px;
 height:150px;
 overflow:hidden;
}
#marquee_replacement p.spacer{
 height:150px;
}
</style>


<script type="text/javascript">
// <!--
var speed = 1; // change scroll speed with this value
/**
 * Initialize the marquee, and start the marquee by calling the marquee function.
 */
function init(){
  var el = document.getElementById("marquee_replacement");
  el.style.overflow = 'hidden';
  scrollFromBottom();
}
 
var go = 0;
var timeout = '';
/**
 * This is where the scroll action happens.
 * Recursive method until stopped.
 */
function scrollFromBottom(){
  clearTimeout(timeout);
  var el = document.getElementById("marquee_replacement");
  if(el.scrollTop >= el.scrollHeight-150){
    el.scrollTop = 0;
  };
  el.scrollTop = el.scrollTop + speed;
  if(go == 0){
    timeout = setTimeout("scrollFromBottom()",50);
  };
}
 
/**
 * Set the stop variable to be true (will stop the marquee at the next pass).
 */
function stop(){
  go = 1;
}
 
/**
 * Set the stop variable to be false and call the marquee function.
 */
function startit(){
  go = 0;
  scrollFromBottom();
}
// -->
</script>




</head>



<BODY onload="startit()">

    
<div id="container">

<div id="holdall">

<div id="marquee_replacement" onmouseout="startit();" onmouseover="stop();">
<p class="spacer"></p>
<p>line 1</p>
<p>line 2</p>
<p>line 3</p>
<p>line 4</p>
<p class="spacer"></p>
</div>

</div>


</div>

</body>
</html>

Open in new window

0
 
LVL 7

Expert Comment

by:Animasu
ID: 33596748
Awesome, Glad you fixed it.

- Animasu
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP get fieds value 2 22
links not working 2 27
How to get chosen background-color on every line? 10 21
toggle content 12 25
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

733 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