473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Div Positioning

Hi

I would like to have 2 Divs one on the other.
The purpose is to show a progress bar and percentage completed
on top of the progress bar like

-------------------
| 30 % |
-------------------

But I could not relatively position the two DIVs
inside a Table.If i relatively position the DIVs, two DIVs
are shown one below the other.If i absolutely position the DIVs,
on resizing two DIVs are changing their positions. Is there any way to
relatively position the DIVs ? I am working on IE 6 and NN 7.

Regards
Prasanna.
Jul 20 '05 #1
5 5809
kp*******@rediffmail.com (K.Prasanna Kumar) writes:
-------------------
| 30 % |
-------------------

But I could not relatively position the two DIVs
inside a Table.If i relatively position the DIVs, two DIVs
are shown one below the other.If i absolutely position the DIVs,
on resizing two DIVs are changing their positions. Is there any way to
relatively position the DIVs ? I am working on IE 6 and NN 7.


Try this:
---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>Progress Bar Test</title>
<style type="text/css">
.progressBar {
position:relative;
width:100px;
height:1.5em;
text-align: center;
background:white;
color:black;
border:1px solid black;
}
.progressBar .progress {
position:absolute;
top:0px;
left:0px;
width:100px;
height:1.5em;
background:blue;
color:white;
overflow:hidden;
clip: rect(0px,0px,1.5em,0px);
}
</style>
</head>
<body>
<div class="progressBar"><span id="content1">0%</span>
<div class="progress" id="progressID"><span id="content2">0%</span>
</div>
</div>
<script type="text/javascript">
function setProgress(id,pct,cnt1,cnt2) {
document.getElementById(id).style.clip="rect(0,"+p ct+"px,1.5em,0px)";
document.getElementById(cnt1).firstChild.nodeValue = pct+"%";
document.getElementById(cnt2).firstChild.nodeValue = pct+"%";
}
var pct = 0;
function progress() {
pct++;
setProgress("progressID",pct,"content1","content2" );
if (pct<100) setTimeout(progress,100);
}
progress();
</script>
</body>
</html>
---
It fails in Opera, because their implementation of the CSS clip
property only clips the content, not the background. I'll ask them if
that is correct behavior.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Great! The code works fine with both in IE6 and NN7.!
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<fz**********@hotpop.com>...
kp*******@rediffmail.com (K.Prasanna Kumar) writes:
-------------------
| 30 % |
-------------------

But I could not relatively position the two DIVs
inside a Table.If i relatively position the DIVs, two DIVs
are shown one below the other.If i absolutely position the DIVs,
on resizing two DIVs are changing their positions. Is there any way to
relatively position the DIVs ? I am working on IE 6 and NN 7.


Try this:
---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>Progress Bar Test</title>
<style type="text/css">
.progressBar {
position:relative;
width:100px;
height:1.5em;
text-align: center;
background:white;
color:black;
border:1px solid black;
}
.progressBar .progress {
position:absolute;
top:0px;
left:0px;
width:100px;
height:1.5em;
background:blue;
color:white;
overflow:hidden;
clip: rect(0px,0px,1.5em,0px);
}
</style>
</head>
<body>
<div class="progressBar"><span id="content1">0%</span>
<div class="progress" id="progressID"><span id="content2">0%</span>
</div>
</div>
<script type="text/javascript">
function setProgress(id,pct,cnt1,cnt2) {
document.getElementById(id).style.clip="rect(0,"+p ct+"px,1.5em,0px)";
document.getElementById(cnt1).firstChild.nodeValue = pct+"%";
document.getElementById(cnt2).firstChild.nodeValue = pct+"%";
}
var pct = 0;
function progress() {
pct++;
setProgress("progressID",pct,"content1","content2" );
if (pct<100) setTimeout(progress,100);
}
progress();
</script>
</body>
</html>
---
It fails in Opera, because their implementation of the CSS clip
property only clips the content, not the background. I'll ask them if
that is correct behavior.

/L

Jul 20 '05 #3
kp*******@rediffmail.com (K.Prasanna Kumar) writes:
Great! The code works fine with both in IE6 and NN7.!


Sadly it doesn't work in Opera 7. Until I find out whether that
is deliberate, I have made a different version using the width
property:
---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>Progress Bar Test</title>
<style type="text/css">
.progressBar {
position:relative;
width:100px;
height:1.5em;
text-align: center;
background:white;
color:black;
border:1px solid black;
}
.progressBar .progress {
position:absolute;
top:0px;
left:0px;
width:100px;
height:1.5em;
overflow:hidden;
}
.pcontent {
background:blue;
width:100px;
height:1.5em;
color:white;}
</style>
</head>
<body>
<div class="progressBar"><span id="content1">0%</span>
<div class="progress" id="progressID"><div
class="pcontent" id="content2">0%</div>
</div></div>
<script type="text/javascript">
function setProgress(id,pct,cnt1,cnt2) {
document.getElementById(id).style.width = pct+"px";
document.getElementById(cnt1).firstChild.nodeValue = pct+"%";
document.getElementById(cnt2).firstChild.nodeValue = pct+"%";
}

var pct = 0;
function progress() {
pct++;
setProgress("progressID",pct,"content1","content2" );
if (pct<100) setTimeout(progress,100);
}
progress();
</script>
</body>
</html>
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
kp*******@rediffmail.com (K.Prasanna Kumar) writes:
Now you are using height 1.5em for both the divs. Can u pl detail me what is
em? is it 150 % ?
1.5 em is 150% of the font size.

I usually give my lengths in em's, because I am firmly against
changing the users preferred font size, and any fixed size design
will blow up for people with larger or smaller fonts than expected.
I want to have a progress bar of height 15px. But if i change height to 15px.
The outer DIV is not showing the correct Height.
That is probably because the outer div contains text, so it will not accept
being smaller than one line of text.
Can u please give the height in 15px.?


You can try adding "line-height:15px;font-size:15px;" to the
..progressBar CSS rule. That should keep the text from pushing the
boundaries of the div.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Hey Great. Works fine.
Are u a Stylesheet Genius :-) ?

[where u get these CSS properties
for all objects ? ;-) ]

Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<fz**********@hotpop.com>...
kp*******@rediffmail.com (K.Prasanna Kumar) writes:
Now you are using height 1.5em for both the divs. Can u pl detail me what is
em? is it 150 % ?


1.5 em is 150% of the font size.

I usually give my lengths in em's, because I am firmly against
changing the users preferred font size, and any fixed size design
will blow up for people with larger or smaller fonts than expected.
I want to have a progress bar of height 15px. But if i change height to 15px.
The outer DIV is not showing the correct Height.


That is probably because the outer div contains text, so it will not accept
being smaller than one line of text.
Can u please give the height in 15px.?


You can try adding "line-height:15px;font-size:15px;" to the
.progressBar CSS rule. That should keep the text from pushing the
boundaries of the div.

/L

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bryan R. Meyer | last post by:
Hello Everyone, The problem of browser resizing has become an issue for me. While redesigning my webpage, I set the left and right margins to be auto so that my content would be centered. ...
4
by: Jane Withnolastname | last post by:
I am trying to re-work an old site by replacing the html with css. On the main page, I have a logo image which I needed centred on the initial screen. I found the solution here:...
14
by: Harlan Messinger | last post by:
What am I not understanding about the definition of { position: absolute; }? "The box's position (and possibly size) is specified with the 'left', 'right', 'top', and 'bottom' properties. These...
6
by: rajek | last post by:
I posted a similar question yesterday, but didn't get an answer that resolved the issue. (Thanks to those who tried though.) The background: I've read in books and online that if you have one...
11
by: NS | last post by:
I am relativly new to css positioning and have a question regarding the display of a DHTML pop-up Here is the basic HTML I am using: <html> <head> <script language="JavaScript"> <!--
1
by: Charles Harrison Caudill | last post by:
with tables there is a clean and algorithmic way to organize things, but with css which is, once you get it working, much cleaner, I have to tweak and patch and hope and pray and curse before...
2
by: Rob R. Ainscough | last post by:
I'm slowly (very slowly) working my way thru the bizarre and sadistic world of control positioning in MultiViews (ASP 2.0). I came across this to help me explain (or attempt to anyway) why my web...
4
by: Alan Silver | last post by:
Hello, Having been a light reader of this ng for a few months now (after several years absence), I have noticed that absolute positioning seems to be considered a Very Bad Thing around here....
9
by: Bill Norton | last post by:
I've been experimenting with floats, positioning and offsets (top, left, etc.) to see what happens when you mix the properties together. All this may be old news to most of you, but it was...
6
by: Mark | last post by:
hi, i'm trying to position something in the top right corner of a container, but i can't seem to figure out how to get it working. here's the html <div class='thumb'><a href='image.jpg'><img...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.