Forum Topic: I hate IE... (negative margins)

(645 views • 30 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/15/08 08:57 AM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

I'm trying to make a nice effect using transparent backgrounds for divs and overlapping them using negative margins. It looks fine in Safari and Firefox, but Internet Explorer won't work.

My only guess is that IE doesn't support negative margins. I looked it up on Google and found something (a supposed "fix" for it) but it didn't work.

Here's my CSS:

body {
	background-color: #FFFFFF;
	color: #333333;
	font-family: Arial;
	font-size: 16px;
	text-align: center;
	margin-top: 0px;
}

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

#header {
	background-image: url(../images/bg_40.png);
	height: 50px;
	margin-left: -50px;
}

#sidebar {
	position: absolute;
	width: 200px;
	margin-left: -50px;
	background-color: #CCCCCC;
}

#content {
	background-image: url(../images/bg_60.png);
	
	width: 700px;
	margin-left: 150px;
	margin-top: -25px;
}

#footer {
	width: 900px;
	margin-left: -50px;
	margin-right: -50px;
	
	font-size: 12px;
	color: #999999;
}

(bg_40 is a background at 40% opacity, bg_60 is the same background at 60%)

And my 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>My Website</title>
<link href="scripts/css.css" type="text/css" rel="stylesheet" />
</head>

<body>

<div id="wrapper">

<div id="header">
<img src="images/logo.png" />
</div>

<div id="sidebar">
[content]
</div>

<div id="content">
[content]
</div>

<div id="footer">
Copyright (C) 2008.  All Rights Reserved.<br />
Site created by Luke Godfrey.
</div>

</div>

</body>
</html>

How can I work around the glitch? Should I change the whole code and use another method, or is there a "CSS Hack" or something I can use?

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/15/08 08:59 AM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

Oh, also...

When I add several lines to "content," the sidebar does not match the height of it. How can I make it the right height based on how tall the "content" div is?

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

BoneIdol

Reply To Post Reply & Quote

Posted at: 8/15/08 09:25 AM

BoneIdol NEUTRAL LEVEL 05

Sign-Up: 08/14/06

Posts: 819

Can you give us an example of what you'd like the end result to be? Unless you use some really busy backgrounds it should be possible to achieve your layout without having to have sibling elements overlapping one another.

Also, have you looked into using position:relative;? This could be a much more stable way for you to achieve your results. This doesn't play with floats too well though.

As to your other problem, divs aren't table cells. They won't stretch to fit the height of a sibling element, but they will stretch to fit a child element. If you nested #content inside #sidebar, then #sidebar would stretch to #content's size.

Just change your CSS to deal with it; a margin-left inside #content set to the width of the #sidebar should do the trick. This could, with some effort, fix your overlapping issue too (just set the margin to be slightly less than the width to simulate a negative margin).

However the easiest way to achieve a stretched look with floating divs is to fake it with tiled background images.

Sufficiently advanced incompetence is indistinguishable from malice.


None

LonLonRanch

Reply To Post Reply & Quote

Posted at: 8/15/08 10:06 AM

LonLonRanch LIGHT LEVEL 17

Sign-Up: 05/22/05

Posts: 320

I think I had a similar problem to this and I think I made a few changes for it to work, like mentioned above I made the div with the negative margin to have a:

position:relative;

If that still doesn't work, instead of doing a margin-left:-40px;

do a left:-40px; or right:40px;

And I think that worked, I also changed the display to display:block; but I can't remember if that was related or not :P


None

BoneIdol

Reply To Post Reply & Quote

Posted at: 8/15/08 10:18 AM

BoneIdol NEUTRAL LEVEL 05

Sign-Up: 08/14/06

Posts: 819

Just re-read this topic (and looked at your CSS this time). Position:absolute needs to die in a fire. If you want a div based layout use floats instead. See http://j-cafe.com/floats.html

Other things:
- Your wrapper div is 800px; this will make people on 800 * 600 pixel resolution have to suffer a horizontal scroll bar. Set the width to be 780 at the very maximum (I prefer 760).

- You're using a px font size; people using IE with poor sight will love you for that (IE refuses to resize pixel font values). Use em units instead.

- Look into using the DX AlphaImageLoader filter to get the transparencies working in IE 6

Sufficiently advanced incompetence is indistinguishable from malice.


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/15/08 10:21 AM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

Thanks! I changed it to position:relative and used "left" instead of "margin-left," etc. It works fine now.

I don't want to use tables to stretch the div, because I got in trouble when I used tables for layouts (people said that it was bad and not to do it). So, how can I stretch the div to the right size? Nesting the content inside of it doesn't work (it messes up the CSS layout because of positioning).

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/15/08 10:31 AM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

Curse IE. Can't people just realize it's terrible and start using Safari? That would make my life infinitely easier >_>

Okay. I changed it to em units.

I can't bring myself to go less than 800 pixels for the wrapper. It's just too small otherwise. If people don't want the horizontal scrollbar, they can get a bigger screen -_-

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

BoneIdol

Reply To Post Reply & Quote

Posted at: 8/15/08 10:36 AM

BoneIdol NEUTRAL LEVEL 05

Sign-Up: 08/14/06

Posts: 819

At 8/15/08 10:21 AM, ShirkDeio wrote: I don't want to use tables to stretch the div, because I got in trouble when I used tables for layouts (people said that it was bad and not to do it). So, how can I stretch the div to the right size? Nesting the content inside of it doesn't work (it messes up the CSS layout because of positioning).

As hinted at above, give your #wrapper a background image that gives you a "faux stretch" on #sidebar. Give it a background-repeat:repeat-y; and do some messing around with background-position until it sits under the menu.

Sufficiently advanced incompetence is indistinguishable from malice.


None

DanielZ

Reply To Post Reply & Quote

Posted at: 8/15/08 12:09 PM

DanielZ DARK LEVEL 08

Sign-Up: 07/30/08

Posts: 566

At 8/15/08 10:31 AM, ShirkDeio wrote: Curse IE. Can't people just realize it's terrible and start using Safari? That would make my life infinitely easier >_>

Just to put in my two cents, it's not only Safari that renders correctly. Almost every modern browser out there renders CSS about equally. Only Internet Explorer screws everything up. A solution would be to use conditional statements to make a separate stylesheet for IE. Something like:

<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="internetexplorer.css" />
<![endif]-->

Also, rumor has it that Internet Explorer 8 will pass the Acid 2 test...
Good job, Microsoft... You've finally made a browser that's compliant to CSS2, when CSS3 is right around the corner...

BBS Signature

None

smulse

Reply To Post Reply & Quote

Posted at: 8/15/08 01:20 PM

smulse EVIL LEVEL 30

Sign-Up: 03/24/05

Posts: 5,928

At 8/15/08 12:09 PM, DanielZ wrote: Also, rumor has it that Internet Explorer 8 will pass the Acid 2 test...
Good job, Microsoft... You've finally made a browser that's compliant to CSS2, when CSS3 is right around the corner...

Or more likely (I've heard rumours) that dirty code checks if it's the acid test and renders the test fine, but it's still heavily uncompliant.

BBS Signature

None

DanielZ

Reply To Post Reply & Quote

Posted at: 8/15/08 03:27 PM

DanielZ DARK LEVEL 08

Sign-Up: 07/30/08

Posts: 566

At 8/15/08 01:20 PM, smulse wrote:
At 8/15/08 12:09 PM, DanielZ wrote: Also, rumor has it that Internet Explorer 8 will pass the Acid 2 test...
Good job, Microsoft... You've finally made a browser that's compliant to CSS2, when CSS3 is right around the corner...
Or more likely (I've heard rumours) that dirty code checks if it's the acid test and renders the test fine, but it's still heavily uncompliant.

Knowing Microsoft, that's pretty believable... Maybe by IE 10, it'll have almost complete CSS2 support... Also, seeing as Microsoft loves copying things, why don't they just copy-and-paste Firefox's sourced code into Internet Explorer? That wouldn't be violating anythings, as Ff is open-source... Honestly, IE is a failed project and Micro$oft should just end it now.

BBS Signature

None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/15/08 04:05 PM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

At 8/15/08 03:27 PM, DanielZ wrote: Stuff

I am pretty sure that if Microsoft would do that they would need to open source the entire IE source due to licensing.

BBS Signature

None

DanielZ

Reply To Post Reply & Quote

Posted at: 8/15/08 04:52 PM

DanielZ DARK LEVEL 08

Sign-Up: 07/30/08

Posts: 566

At 8/15/08 04:05 PM, DearonElensar wrote:
At 8/15/08 03:27 PM, DanielZ wrote: Stuff
I am pretty sure that if Microsoft would do that they would need to open source the entire IE source due to licensing.

But they're Microsoft... Lawsuits and licenses are no threat to them at all.

BBS Signature

None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/15/08 04:59 PM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

At 8/15/08 04:52 PM, DanielZ wrote: But they're Microsoft... Lawsuits and licenses are no threat to them at all.

Don't make me laugh, Microsoft could easily be destroyed through lawsuits.
After all, why do you think they threatening with the 30 patents (if i remember correctly) that Linux was violating instead of suing? (no company is invincible, especially with all the patents etc. that open source friendly company's have)

BBS Signature

None

Relish

Reply To Post Reply & Quote

Posted at: 8/15/08 08:28 PM

Relish NEUTRAL LEVEL 06

Sign-Up: 01/22/08

Posts: 780

I hate IE

Who doesnt?


None

DanielZ

Reply To Post Reply & Quote

Posted at: 8/15/08 10:33 PM

DanielZ DARK LEVEL 08

Sign-Up: 07/30/08

Posts: 566

At 8/15/08 08:28 PM, Relish wrote:
I hate IE
Who doesnt?

The so-called "IT specialist" at my school. He loves IE 5 and 6, and possession of Firefox, Opera, or any other alternative browser is punishable by suspension. Then again, he's also an AOL user... so he can't really be counted as a human...

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/15/08 11:20 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

New question. I'm trying to stretch the left column.

I re-arranged everything to use a tiled background image in #wrapper. It works fine, but because of a "top: -25px;" on my #content, this is leaving an ugly blank spot on the right and the background image is being tiled too many times on the left (25px too much, to be exact).

When I used borders to test it, I found out that the wrapper stretched to accommodate the #content (without the 25px negative margin of #content), making it 25px too tall. Borders also showed me that the #content div didn't contain the blank--it was only in #wrapper.

How can I fix this? I tried moving the footer up by using a -25px margin and adding background-color: #FFFFFF; to it, but that caused a blank to be below that.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/16/08 12:00 AM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

At 8/15/08 11:20 PM, ShirkDeio wrote: Stuff

Can you put the website that has this problem online somewhere?
It would be much easier if we can see and debug it that way :)

BBS Signature

None

Relish

Reply To Post Reply & Quote

Posted at: 8/16/08 08:08 AM

Relish NEUTRAL LEVEL 06

Sign-Up: 01/22/08

Posts: 780

At 8/15/08 10:33 PM, DanielZ wrote: The so-called "IT specialist" at my school. He loves IE 5 and 6, and possession of Firefox, Opera, or any other alternative browser is punishable by suspension. Then again, he's also an AOL user... so he can't really be counted as a human...

What is wrong with him???

Although my school used to have IE mac, it was a nightmare. but recently they upgraded and now the students have a choice between Safari and Firefox.

I used to just bring my own computer.


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/16/08 09:35 AM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

I don't have my own server/space, but I can give you the code:

<!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>My Website</title>
<link href="scripts/css.css" type="text/css" rel="stylesheet" />
</head>

<body>

<div id="header">
<!--It's 50px high->
<img src="images/logo.png" />
</div>

<div id="wrapper">

<div id="sidebar">
test<br />
test<br />
test<br />
test<br />
test<br />
</div>

<div id="content">
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
test<br />
</div>

</div>

<div id="footer">
<br /><br />
Copyright (C) 2008.  All Rights Reserved.<br />
Site created by Luke.
</div>

</body>
</html>

And the CSS:

body {
	background-color: #FFFFFF;
	color: #333333;
	font-family: Arial;
	font-size: 1em;
	text-align: center;
	margin-top: 0px;
}

#wrapper {
	margin-left: auto;
	margin-right: auto;
	
	width: 800px;
	
	background-image: url(../images/bg_gray.png);
	background-repeat: repeat-y;
}

/* Header + IE hacks */
#header {						/* Not IE */
	margin-left: auto;
	margin-right: auto;
	background-image: url(../images/bg_60.png);
	
	height: 50px;
	width: 700px;
	
	position: relative;
	right: 50px;
}
* html #header {				/* IE6 and below */
	margin-left: auto;
	margin-right: auto;
	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/bg_60.png", sizingMethod="scale");
	
	height: 50px;
	width: 700px;
	
	position: relative;
	right: 50px;
}

/* Sidebar + IE hacks */
#sidebar {						/* Not IE */
	position: absolute;
	
	width: 200px;
	background-color: #CCCCCC;
}
*:first-child+html #sidebar {	/* IE7 */
	position: absolute;
	
	width: 200px;
	margin-left: -100px;
	background-color: #CCCCCC;
}

/* Content + IE hacks */
#content {						/* Not IE */
	background-image: url(../images/bg_80.png);
	
	position: relative;
	width: 600px;
	left: 200px;
	top: -25px;
}
*:first-child+html #content {	/* IE7 */
	background-image: url(../images/bg_80.png);
	
	position: relative;
	width: 600px;
	left: 100px;
	top: -25px;
}
* html #content {				/* IE 6 and below */
	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../images/bg_80.png", sizingMethod="scale");
	
	position: relative;
	width: 600px;
	left: 100px;
	top: -25px;
}

#footer {
	background-color: #FFFFFF;
		
	position: relative;
	margin-left: auto;
	margin-right: auto;
	top: -25px;
	width: 800px;
	
	font-size: .75em;
	color: #999999;
}

Again, bg_80 and similar filenames are semi-transparent images (80 = 80% opacity, etc)

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/16/08 10:33 AM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

I'll take a look soon, one thing tho use Conditional Comments instead of hacks to solve CSS problems.

BBS Signature

None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/16/08 10:36 AM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

At 8/16/08 10:33 AM, DearonElensar wrote: I'll take a look soon, one thing tho use Conditional Comments instead of hacks to solve CSS problems.

That should have been IE CSS problems >.> (i just woke up so i'll just use that as an excuse ;)

BBS Signature

None

Relish

Reply To Post Reply & Quote

Posted at: 8/16/08 11:51 AM

Relish NEUTRAL LEVEL 06

Sign-Up: 01/22/08

Posts: 780

(i just woke up so i'll just use that as an excuse ;)

riiiighttt lol ;)


None

TheRadicalOne

Reply To Post Reply & Quote

Posted at: 8/16/08 03:20 PM

TheRadicalOne FAB LEVEL 35

Sign-Up: 11/28/05

Posts: 4,198

At 8/15/08 10:33 PM, DanielZ wrote:
At 8/15/08 08:28 PM, Relish wrote:
I hate IE
Who doesnt?
The so-called "IT specialist" at my school. He loves IE 5 and 6, and possession of Firefox, Opera, or any other alternative browser is punishable by suspension. Then again, he's also an AOL user... so he can't really be counted as a human...

Apparently it's all too easy to gain the title of "IT specialist..."


None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/16/08 04:43 PM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

Eh, upload all the images please because i can't do much with it like this :( (just zip them and put them on Rapidshare or Megaupload or some site like that)

BBS Signature

None

DanielZ

Reply To Post Reply & Quote

Posted at: 8/16/08 07:04 PM

DanielZ DARK LEVEL 08

Sign-Up: 07/30/08

Posts: 566

Or you can upload the damn images to Z-Up... no registration nor waiting required... Better yet, go to 110mb.com or freewebs and upload the html... It's kind of hard to help you when we don't know what you're aiming to do...

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/18/08 12:34 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

>_>

I'll just fix it myself. There's only one image in the HTML, and it's just a banner--not to mention that it's nowhere near the problem. The other images are one-pixel images that I already explained.

Seriously, copy and paste into Notepad and save as HTML...

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

DearonElensar

Reply To Post Reply & Quote

Posted at: 8/18/08 01:14 PM

DearonElensar LIGHT LEVEL 18

Sign-Up: 06/10/02

Posts: 1,731

There are:
../images/bg_gray.png
../images/bg_60.png
../images/bg_80.png
All linked in your CSS, why don't you try the HTML/CSS without images so you can see that it is pretty unclear what is going on.

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/18/08 04:17 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

-_-

I did what the guy above said. He said to tile a background image to make the sidebar appear to stretch out. That's what bg_gray is. The other ones are single-pixel images so I could use transparencies--just change it to colors.

All I want to know is why one div (wrapper) stretches farther than the two contained divs (sidebar and content) and how to prevent it. The images don't matter. All that matters is that wrapper is stretching 25px too much, causing an ugly blank spot.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 8/18/08 05:02 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

I just used a table to stretch it out. People said I was using tables incorrectly and being "n00bish" for using tables in the layout. But it's the only way I can find to make this work on all browsers with no problems.

It works perfectly with a table.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


All times are Eastern Standard Time (GMT -5) | Current Time: 06:30 PM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!