Solved

Absolute Positioning not exact

Posted on 2006-10-31
13
126 Views
Last Modified: 2010-04-09
Or is it me.

I have a blank HTML page.  I wanted a div that took up 10% of the top of the screen and 100% width.

I then wanted 3 divs below this.  Each div went the rest of the height of the screen so 90% and each are to be 33.3% wide.  Well first thing that is wrong is that when I display this page, each of the 3 div's at 30% are not exactly touching, they're both off slightly.  Also the 3 divs are more wide together then the 100% width bar at the top.  Whats the deal with this?  Do percentages not work well?
0
Comment
Question by:cophi
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 30

Expert Comment

by:Steggs
ID: 17844298
Greetings cophi,

What browser are you using?


0
 

Author Comment

by:cophi
ID: 17844314
IE 6
0
 

Author Comment

by:cophi
ID: 17844358
I actually tried FIREFOX and it seemed to work fine on that, any reason why it doesn't work properly on IE 6
0
 
LVL 30

Expert Comment

by:Steggs
ID: 17844370
Percentages work fine.

I can tell you now that IE6 will add padding if you do not set padding to 0, also make sure you have margins set to 0. Also, remove whitespace from your html as ie6 will play all kinds of tricks if you give it some whitespace.

Regards
0
 
LVL 17

Expert Comment

by:gops1
ID: 17844401
use css specific to IE

for ex:

.testCss{
       width:33.3%;
}

/* For IE */
* html .testCss{
         width:40%;
}
0
 

Author Comment

by:cophi
ID: 17845467
I have code such as.... <div style="position: absolute; width: 100%; height: 10%; z-index: 1; left: 0px; top: 0px; padding: 0px"

It for some reason just won't work right in IE
0
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.

 
LVL 30

Expert Comment

by:Steggs
ID: 17845524
I wouldnt recommend using positioning for layout. Use floats instead.
0
 

Author Comment

by:cophi
ID: 17849158
ok well i don't understand floats very well.

how would i create 4 divs using floats.  1 div on the top thats 10% height and 100% wide, and then 3 div's underneath that, equally spread, taking up the rest of the screen?
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 17853838
show us your code. it will help see what problems you have.
0
 

Author Comment

by:cophi
ID: 17857863
<div style="position: absolute; width: 100%; height: 10%; z-index: 1; left: 0px; top: 0px; padding: 0px" id="1">
<img src="a.JPG" height="100%" width="100%"></div>
<div style="position: absolute; width: 30%; height: 90%; z-index: 2; left: 0px; top: 10%; padding: 0px" id="2">
<img src="b.jpg" height="100%" width="100%"></div>
<div style="position: absolute; width: 40%; height: 90%; z-index: 3; left: 30%; top: 10%; padding: 0px" id="3">
STUFF</div>
<div style="position: absolute; width: 30%; height: 90%; z-index: 5; left: 70%; top: 10%; padding: 0px" id="5">
<img src="c.jpg" height="100%" width="100%"></div>

The renders correctly in Firefox not IE
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 18124072
put this in the body.. this will fix the first div

<body topmargin=0 leftmargin=0 rightmargin=0>
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 18124139
this was the closest i could come to what you're looking for. I put background colors in it so you can see where it is placed. The only issue is the first div, which has a fixed height... I'll try and see if I can make it completely % based.


<html>
<body topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>
<div style="position: absolute; width:100%; height: 50px; z-index: 1; left: 0px; top: 0px; padding: 0px;border-color:red;background-color:brown;" id="1">
<img src="a.JPG">top</div>

<div style="position: absolute; width: 30%; height: 93%; z-index: 2; left: 0px; top: 50px; padding: 0px;background-color:gray;" id="2"><img src="b.jpg">x</div>

<div style="position: absolute; width: 40%; height: 93%; z-index: 3; left: 30%; top:50px; padding: 0px;" id="3">STUFF</div>

<div style="position: absolute; width: 30%; height: 93%; z-index: 4; left: 70%; top: 50px; padding: 0px;background-color:gray;" id="5"><img src="c.jpg">x</div>

</body>
</html>
0
 
LVL 16

Accepted Solution

by:
ThinkPaper earned 500 total points
ID: 18124151
ok.. well it seems to work..

<html>
<body topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>
<div style="position: absolute; width:100%; height: 20%; z-index: 1; left: 0px; top: 0px; padding: 0px;border-color:red;background-color:brown;" id="1">
<img src="a.JPG">top</div>

<div style="position: absolute; width: 30%; height: 80%; z-index: 2; left: 0px; top: 20%; padding: 0px;background-color:gray;" id="2"><img src="b.jpg">x</div>

<div style="position: absolute; width: 40%; height: 80%; z-index: 3; left: 30%; top: 20%; padding: 0px;" id="3">STUFF</div>

<div style="position: absolute; width: 30%; height: 80%; z-index: 4; left: 70%; top: 20%; padding: 0px;background-color:gray;" id="5"><img src="c.jpg">x</div>

</body>
</html>
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

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article discusses four methods for overlaying images in a container on a web page
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

13 Experts available now in Live!

Get 1:1 Help Now