Solved

Problem with Chrome,FireFox border

Posted on 2011-02-27
5
687 Views
Last Modified: 2012-08-13
Hi,

I have the attached code that creates very nice horizontal bars graph in IE.
See attached picture IE-bars.
When I try it in Chrome or in FireFox,
It is messed up (see arrached picture Chrone-bars).
 Chrom-bars IE-Bars
function showTotoBarGraph(id,j,percent,n)
{
 var obj = document.getElementById(id);
 var colors=new Array("#52FF7A","#FF4D9A","#6EE7FF");
 
 obj.style.width ="100px";
 obj.style.height="10px";
 obj.style.border="1px solid black";
 obj.style.margin="2px"; 
 obj.style.backgroundColor = "white";

 obj.innerHTML='<div>'+percent+'%</div>';
 obj=obj.getElementsByTagName("div")[0];
 obj.style.fontSize="10px"; 
 
 obj.style.border="1px none black";
 obj.style.height="100%";

 obj.style.backgroundColor = colors[j];
 obj.style.width = percent + "px";
 obj.style.textAlign = "center";
 if (j == 1)
 obj.style.color="#FFFFFF";
}

Open in new window

0
Comment
Question by:VapiSoft
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:R-Byter
ID: 34992116
It seems that you're missing float: left.
0
 

Author Comment

by:VapiSoft
ID: 34992134
What is it?
Where do I put it?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 34992492
This works in Firefox and Chrome as well as IE8.  Since I don't have your complete code, I don't know what the difference is.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>JS Bar Graph</title>
<script type="text/javascript">
<!--
function showTotoBarGraph(id,j,percent,n)
{
 var obj = document.getElementById(id);
 var colors=new Array("#52FF7A","#FF4D9A","#6EE7FF");
 
 obj.style.width ="150px";
 obj.style.height="20px";
 obj.style.border="1px solid black";
 obj.style.margin="2px"; 
 obj.style.backgroundColor = "white";

 obj.innerHTML='<div>'+percent+'%</div>';
 obj=obj.getElementsByTagName("div")[0];
 obj.style.fontSize="13px"; 
 
 obj.style.border="1px none black";
 obj.style.height="100%";

 obj.style.backgroundColor = colors[j];
 obj.style.width = (percent*1.5) + "px";
 obj.style.textAlign = "center";
 if (j == 1)
 obj.style.color="#FFFFFF";
}
// -->
</script>
</head>
<body>
<h1>JS Bar Graph</h1>
<div id="g1">
<script type="text/javascript">
<!--
showTotoBarGraph("g1",'2','50','1')
// -->
</script>
</div>
<div id="g2">
<script type="text/javascript">
<!--
showTotoBarGraph("g2",'0','50','2')
// -->
</script>
</div>
<div id="g3">
<script type="text/javascript">
<!--
showTotoBarGraph("g3",'1','50','3')
// -->
</script>
</div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:VapiSoft
ID: 34993986
What I found is that I has the graph inside <span>
When I saw your code, I realized that this is the difference.
Thanks.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 34994110
Cool, thanks for the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

914 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

17 Experts available now in Live!

Get 1:1 Help Now