Solved

Absolute Positioning not exact

Posted on 2006-10-31
13
127 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to avoid jquery conflicts in Wordpress ? 4 32
Centered Image 2 27
would like the bottom of this page to be smaller 3 27
Place text over image using CSS 6 42
This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

813 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

14 Experts available now in Live!

Get 1:1 Help Now