Forum Moderators: not2easy

Message Too Old, No Replies

Whitespace in between divs

         

andrewsmd

2:45 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am having issues with placing divs right by each other. There is some space between them and I need them do display right next to each other. The footer div has a little space above it and in IE the bottomRightMain div also has some space above it. Can anyone tell me what is wrong with this code. Here is the css
/* CSS Document */
body{
margin: 0 0 0 0;
padding: 0 0 0 0;
}
#header{
margin: 0 0 0 0;
padding: 0 0 0 0;
border: 0;
}
#main{
background-color:#0033CC;/*396aac*/
margin: 0 0 0 0;
padding: 0 0 0 0;
border: 0;
}
#leftMain{
display: inline;
margin: 0 0 0 0;
padding: 0 0 0 0;
border: 0;
}
#topRightMain{
display: inline;
position: relative;
top: -10.6em;
left: 0em;
margin: 0 0 0 0;
padding: 0 0 0 0;
border: 0;

}
#bottomRightMain{
display: inline;
margin-left: 7em;
margin-bottom: 0;
margin-top: 0;
padding: 0 0 0 0;
border: 0;
}
#footer{
margin: 0 0 0 0;
padding: 0 0 0 0;
}

And here is the html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Two Rivers Public Health</title>
<link rel="stylesheet" type="text/css" href="styles/stylesheet.css">
</head>
<body>
<div id="total">
<div id="header"><img src="templateimages/body/template_r1_c1.jpg"
alt="Two Rivers Logo" width="325" height="124" /><img
src="templateimages/body/template_r1_c3.jpg" alt="connecting people"
width="475" height="124" /></div>
<div id="main">
<div id="leftMain"><img
src="templateimages/body/template_r2_c1.jpg" /></div><div id="topRightMain"><img
src="templateimages/body/template_r2_c2.jpg" /><img
src="templateimages/body/template_r2_c4.jpg" /><img
src="templateimages/body/template_r2_c5.jpg" /><div id="bottomRightMain"><img
src="templateimages/body/template_r3_c2.jpg" /></div><div id="footer"><img src="templateimages/body/template_r4_c1.jpg"
alt="Footer" /></div>
</div>
</body>
</html>

Thanks

D_Blackwell

5:01 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) The markup does not validate. There are two missing </div>. Assume that one is at the end of the document. The other between #topRightMain and bottomRightMain? ?

2) You can shorthand all of the margin: and padding: to:
{margin: 0; padding: 0;}

3) Most, if not all of the {border: 0;} can probably be cut. {border: none; will be default:).

4) For that matter, after testing, most of the {margin: 0; padding: 0;} can probably be cut as well. There will be none by default for most of these containers.

5) Validating the HTML should take care of the #footer. Am having no issue with "right by each other", unless you mean containers inside #main. If so, I'd rather see updated markup and additional description of issue before looking at that and the extra space at the top in IE. Stripping out the images and fixing the skeleton might be the easiest way to find out where that is coming from. Maybe temporarily add some height for a better look. After all, I have no clue what the dimensions of the images are. Don't think that they are the problem, but a problem for my guessing at what is truly needed.

6) For now I would just put a background-color: behind all of the containers to see what issues remain after validation.

D_Blackwell

5:16 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would take a hard look at how and why on the positioning here and what the effect is - also perhaps the selection of inline. ?

#topRightMain{
display: inline;
/*position: relative;
top: -10.6em;
left: 0;*/
background-color: green;
}

andrewsmd

5:37 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It has to be inline because the leftMain image goes down the left side and then the toprightmain needs to be aligned with the top of the leftMain div. That is why the top -10.6 is there. Because when the images in that div are displayed, they align with the bottom of the leftMain image. I tried setting the v-aling to top in that div but had no success so I manually moved the images up. I'm not having an issue with that div anyways, it is the div below it.

D_Blackwell

6:08 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'll take your word for the inline, though remain concerned that images may be forcing correct display of flawed code, specifically the display of #topRightMain. Can't say. You know the needs, issues, and rendering.

At any rate, the IE issue with the 'space' between #header and #main is clearly coming from the images in the #header and is easily illustrated by commenting them in and out in IE. (FF and Opera render correctly.)

Fix 1 - Add {height: 124px;} to #header.

Fix 2 (preferred) - Add the same as a conditional specific to IE.

<!--[if gte IE 7]>
<style type="text/css" media="all">
#header {
height: 124px;
}
</style>
<![endif]-->

<!--[if gte IE 7]>
Or whatever versions need hacking.

andrewsmd

7:29 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not for sure I understand what you mean. What do you mean it is coming from the images themselves.

D_Blackwell

8:22 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...illustrated by commenting them in and out in IE.

<!--##########
<img src="aaa.jpg" alt="Two Rivers Logo" width="325" height="124" /><img src="bbb.gif" alt="connecting people" width="475" height="124" />
-->
TEXT FOR A BIT OF ILLUSTRATION.
</div>

I'm not for sure I understand what you mean. What do you mean it is coming from the images themselves.

The way that IE is adding a dab of space. It is the addition of the images that triggers the glitch. Take them out, and the extra space added to that container goes away.

I'm not saying that the suggested solution is the only option. It is an option that works, though you may be offered other and preferable options.

andrewsmd

8:29 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So commenting the images out may work, but I don't see how that solves my issue. I need these images in the page. I'm not trying to be difficult, I just don't see how getting rid of the images solves my problem. Thanks,

D_Blackwell

8:37 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Commenting out the images and just plugging in some text illustrates that IE is adding a touch of space beneath the images. This, IMO, identifies the issue to be fixed; allowing work to begin on a solution.

Comment the images back in and proceed.

Fix 1 - Add {height: 124px;} to #header.

Fix 2 (preferred) - Add the same as a conditional specific to IE.

<!--[if gte IE 7]>
<style type="text/css" media="all">
#header {
height: 124px;
}
</style>
<![endif]-->

<!--[if gte IE 7]>
Or whatever versions need hacking.

andrewsmd

8:56 pm on Oct 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, if pinpointing that the images are the culprit, do you have any suggested fixes. I have tried setting the margin of each pic and each div. The funny thing is, the images
div id="header"><img src="templateimages/body/template_r1_c1.jpg"
alt="Two Rivers Logo" width="325" height="124" /><img
src="templateimages/body/template_r1_c3.jpg" alt="connecting people"
width="475" height="124" /></div>
<div id="main">
<div id="leftMain"><img
src="templateimages/body/template_r2_c1.jpg" /></div><div id="topRightMain"><img
src="templateimages/body/template_r2_c2.jpg" /><img
src="templateimages/body/template_r2_c4.jpg" /><img
src="templateimages/body/template_r2_c5.jpg" />

all display the way they are supposed to. I have most of the div properties the same. Any thoughts

andrewsmd

3:00 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So I have gotten this to work a little better but I am having a strange issue now. I am getting images to display next to each other, except for one image. When I try to add the div "mainRight" it goes to the next line. How it should look is mainLeft, mainMiddle, and mainRight are all inline next to each other and then mainBottom goes beneath those three. The problem is, once I add the mainRight div, it goes to the next line. I can add the mainRight div two or three times and it displays fine but as soon as I add the mainRight, it goes to the next line. Any ideas why? Here is my code

* {
padding: 0;
margin: 0;
}

body {

}

#wrapper {
margin-left: auto;
margin-right: auto;
width: 800px;
}

#header {
background-image: url(templateimages/body/template_r1_c1.jpg);
float: left;
padding: 0px;
border: 0;
margin: 0px 0px 0px 0px;
width: 325px;
height: 124px;
}

#headerRight {
float: right;
padding: 0px;
border: 0;
margin: 0px 0px 0px 0px;
width: 475px;
height: 124px;
background-image: url(templateimages/body/template_r1_c3.jpg);
}

#leftcolumn {
border: 0px;
margin: 0px 0px 0px 0px;
padding: 0px;
height: 427px;
width: 113px;
float: left;
background-image: url(templateimages/body/template_r2_c1.jpg);
}

#main {
float: left;
border: 0px;
margin: 0px 0px 0px 0px;
padding: 0px;
height: 350px;
width: 678px;
display: inline;
}

#mainLeft {
border: 0px;
margin: 0px 0px 0px 0px;
padding: 0px;
background-image: url(templateimages/body/template_r2_c2.jpg);
height: 257px;
width: 335px;
float: left;

}
#mainMiddle{
border: 0px;
margin: 0px 0px 0px 0px;
padding: 0px;
background-image: url(templateimages/body/template_r2_c4.jpg);
height: 257px;
width: 95px;
float: left;

}
#mainRight{
border: 0px;
margin: 0px 0px 0px 0px;
padding: 0px;
background-image: url(templateimages/body/test.png);
height: 257px;
width: 260px;
float: right;
clear: both;

}

#mainBottom{
border: 0px;
margin: 0px 0px 0px 0px;
padding: 0px;
float: left;
background-image:(templateimages/body/template_r3_c2.jpg);
width: 687px;
height: 170px;
}

#footer {
width: 800px;
clear: both;
border: 0px;
margin: 0px 0px 0px 0px;
height: 49px;
padding: 0px;
background-image: url(templateimages/body/template_r4_c1.jpg);
}

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Fixed Width CSS Layouts - 2 Column - fw-12-2-col</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>

<body>

<!-- Begin Wrapper -->
<div id="wrapper">

<!-- Begin Header -->
<div id="header">

</div>
<!-- End Header -->

<!-- Begin Header -->
<div id="headerRight">

</div>
<!-- End Header -->

<!-- Begin Left Column -->
<div id="leftcolumn">

</div>
<!-- End Left Column -->

<!-- Begin Right Column -->
<div id="main">
<div id="mainLeft">
</div>
<div id="mainMiddle">
</div>
<div id="mainRight">
</div>
</div>
<!-- End Right Column -->

<!-- Begin Footer -->
<div id="footer">

</div>
<!-- End Footer -->

</div>
<!-- End Wrapper -->

</body>
</html>

D_Blackwell

5:36 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) #main is stipulated as {width: 678px;}

2) #main holds:
#mainLeft {width: 335px;},
#mainMiddle {width: 95px;},
#mainRight {width: 260px;},

3) Total width of the three containers wrapped by #main is 690px; - This exceeds the capacity of #main, and it will shift #mainRight down because there is no room.

4) With this markup, whether #mainRight is floated right or left makes no difference whatsoever. However, {clear: both;} is declared, so it does what it is supposed to do and clears.

5) Thus, two problems that both cause #mainRight to drop. Fix either one and there will be no effect. They must both be dealt with.

6)

2) You can shorthand all of the margin: and padding: to:
{margin: 0; padding: 0;}

3) Most, if not all of the {border: 0;} can probably be cut. {border: none; will be default:).

4) For that matter, after testing, most of the {margin: 0; padding: 0;} can probably be cut as well. There will be none by default for most of these containers.

{margin: 0;} is more efficient than {margin: 0px 0px 0px 0px;}

The following is a global declaration, so no need to repeat anywhere else.
* {
padding: 0;
margin: 0;
}

You might want the following;
html, body {
padding: 0;
margin: 0;
}

I commented out all of the {margin: 0; padding: 0; border: 0;} Default is 0 for each in all of those containers in each of several tested browsers.

Other than that, it is just extra code that isn't doing anything. If you just felt a need to set them all to 0 anyway, then one declaration for all would be simpler. If the template changes, you can always remove one of the ids from the list and then specify changes.

#header, #headerRight, #leftcolumn, #main, #mainLeft, #mainMiddle, #mainRight, #mainBottom, #footer {
margin: 0;
padding: 0;
border: none;
}

7) What is the purpose of {display: inline;} in #main? It is already floated left with width and height specified. ? /*display: inline;*/

andrewsmd

6:15 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks you helped me out. I'm not a css person. I'm usually just a back end guy and I was thrown into this so I was trying to do it quickly without a whole lot of css knowledge.

D_Blackwell

7:35 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem at all. I noticed in your profile that your posts are mostly on PHP and Microsoft servers.

Hope that you can drag me through a problem when I come crying to the PHP forum with a question. I enjoy PHP, can manipulate existing code okay to fit needs, but mostly am really lousy at ground up building. Haven't had the right circumstances in that area to really learn correctly - to start with nothing and not only build something that works, but is also lean, clean, efficient.....

...thrown into this...

LOL - Yeah, I've been involved in a lot of "Hey, as long as you are doing these items, why don't you go ahead and do those too."

Uh. Well. Cause I don't do everything - but I can see that it gets done.

(Extra $$$ for add-on and enough extra to get a cut from anything given over to someone else - at least enough extra to cover extra trouble, communication, plus fair extra profit that I should get as designer/developer/consultant - whatever the circumstances appropriate to the situation.)

andrewsmd

7:43 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can definitely help out in the php development area. I did that kind of work for two years before moving to .net. My biggest strength is in hosting and dns matters, which is where 90% of tech companies screw something up.