Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2007, 03:58 AM   PM User | #1
name _F1
Regular Coder

 
Join Date: Jun 2006
Posts: 225
Thanks: 6
Thanked 3 Times in 3 Posts
name _F1 is on a distinguished road
Pixel-perfect fluid widths

I am trying to achieve a layout which adjusts to the resolution of the user's screen, but also lines up with other elements on the page.

I want to have two boxes at the top of the page, next to each other (floated left), with some more boxes below them which line up with the edges of the boxes above.

Code:
+--------+ +--------+
| Box 1  | | BOX 2  |
+--------+ +--------+
+-------------------+
|    BOX 3          |
+-------------------+
+-------------------+
|    BOX 4          |
+-------------------+
Everything lines up perfectly if I use % margins, until I add borders. If I add a 1px border, everything goes out of line. This is one of the biggest downfalls with CSS, in my opinion. Is there any way to make everything line up while still using borders and fluid widths, short of using Javascript to determine the viewport dimensions?
name _F1 is offline   Reply With Quote
Old 10-28-2007, 01:31 AM   PM User | #2
jlhaslip
Regular Coder

 
Join Date: Feb 2007
Location: Canada
Posts: 924
Thanks: 10
Thanked 56 Times in 55 Posts
jlhaslip is on a distinguished road
What do you want the borders on? Every div? the entire page?
Where is the code you are working with?
Trying to help you here...
jlhaslip is offline   Reply With Quote
Old 10-28-2007, 04:17 AM   PM User | #3
name _F1
Regular Coder

 
Join Date: Jun 2006
Posts: 225
Thanks: 6
Thanked 3 Times in 3 Posts
name _F1 is on a distinguished road
Sorry, I was in a bit of a hurry when I posted so I forgot some information. I want the borders on every DIV.

PHP Code:
<html>
<
head>
<
style type="text/css">
div {
  
border1px solid black;
  
margin:1%;
  
height:50px/* Ignore this, it's just to expand the DIVS */
  
padding:0;
}
div.head {
  
width:47.5%; /* 48% widths wrap to the next line, because of the borders */
  
float:left;
}
div.body {
  
width:98%;
  
clear:both;
}
</
style>
</
head>
<
body>
<
div class="head"></div>
<
div class="head">Right edge edge of this DIV...</div>
<
div class="body">...should align with the right edge of this DIV</div>
<
div class="body"></div>
</
body>
</
html
name _F1 is offline   Reply With Quote
Old 10-28-2007, 07:17 AM   PM User | #4
trigger_tre
Regular Coder

 
Join Date: May 2006
Posts: 290
Thanks: 6
Thanked 14 Times in 14 Posts
trigger_tre is an unknown quantity at this point
I could be wrong because I don't usually use fluid width but.

From my calculations you set width to 98% plus your margin is set to 1%.

So add 1% + 98% + 1% = 100% (100% is the max, but now you decided to add a 1 pixel border to it)

Again let me stress that I don't normally code fluid layouts so I am not sure which gets calculated first.

If the browsers subtract the 1 pixel border from the TOTAL resolution first then from that new total it uses 1 % for margins and 98% for width then you should be ok.

However, logically speaking if the browser takes the TOTAL resolution and makes the margins 1% then the width 98% by the time it tries to calculate the borders its out of fingers to use for counting.

AGAIN I don't know for sure but my guess is that if your using percentages then try to use a percentage for borders too. This might correct the problem.

-trigger
trigger_tre is offline   Reply With Quote
Old 10-28-2007, 07:44 AM   PM User | #5
name _F1
Regular Coder

 
Join Date: Jun 2006
Posts: 225
Thanks: 6
Thanked 3 Times in 3 Posts
name _F1 is on a distinguished road
Unfortunately percentage borders don't work.

With no border, 48% widths on the top DIVs and 98% widths on the bottom DIVs, everything lines up perfectly. When 1px borders are added, the total width becomes slightly larger than 100%, so the second header DIV jumps to the next line.
name _F1 is offline   Reply With Quote
Old 10-29-2007, 09:42 AM   PM User | #6
name _F1
Regular Coder

 
Join Date: Jun 2006
Posts: 225
Thanks: 6
Thanked 3 Times in 3 Posts
name _F1 is on a distinguished road
Can anyone else offer some insight?
name _F1 is offline   Reply With Quote
Old 10-29-2007, 08:30 PM   PM User | #7
jlhaslip
Regular Coder

 
Join Date: Feb 2007
Location: Canada
Posts: 924
Thanks: 10
Thanked 56 Times in 55 Posts
jlhaslip is on a distinguished road
wrapper div?
float them left and right to the boundaries of the wrapper,with/without the borders.
jlhaslip is offline   Reply With Quote
Old 10-30-2007, 04:19 AM   PM User | #8
dcostalis
New Coder

 
Join Date: Oct 2007
Posts: 49
Thanks: 5
Thanked 9 Times in 9 Posts
dcostalis is an unknown quantity at this point
try setting the left and right margins of the top divs individually, and floating the right div to the right.
dcostalis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:38 AM.


Advertisement
Log in to turn off these ads.