---
title: "DIV-strul i Netscape"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/56417-div-strul-i-netscape"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "Palleman"
published: "2002-10-18T15:42:41.000Z"
updated: "2002-10-23T11:21:52.000Z"
replies: 3
views: 196
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/56417-div-strul-i-netscape"
---

# DIV-strul i Netscape

## #1 — Palleman, 2002-10-18T15:42Z

Hej!

Jag sitter och brottas med en DIV-tagg som inte vill som jag vill..
Jag vill centrera DIV-taggen och dess innehåll på sidan, och det  fungerar fin fint i IE men i Netscape ligger den som en blaffa högst upp.. 

Min kod ser ut så här nu:

```
[FONT=arial][RED]<html><head>

<style type="text/css">

	#mycontent {
		border: solid 1px #000;
		padding: 10px;
		background: #f0f0f0;
	}

</style>

<script language="JavaScript">

	function center_content() {
	
		// Browsercheck
		var browser = (navigator.appName);
		
		// Önskad höjd och bredd
		var height = 400;
		var width = 600;

			// Internet Explorer
			if (browser == "Microsoft Internet Explorer") {
				mycontent.style.height = height;
				mycontent.style.width = width;
				mycontent.style.marginTop = (document.body.clientHeight-height)/2;
				mycontent.style.marginLeft = (document.body.clientWidth-width)/2;
			}

			// Netscape
			if (browser == "Netscape") {
				mycontent.style.height = height;
				mycontent.style.width = width;
				mycontent.style.top = (window.innerHeight-height)/2;
				mycontent.style.left = (window.innerWidth-width)/2;
			}

	}

</script>

</head>
<body onresize="location.reload();" onload="center_content();">

<div id="mycontent">
     Detta är innehållet..
</div>

</body></html>[/RED][/FONT]
```

Någon som vet vad jag gör för fel och vad som bör förbättras? :OO 
&nbsp;
&nbsp;
&nbsp;

Permalänk: https://www.webforum.nu/p/56417

## #2 — Jojoxx, 2002-10-18T17:27Z

Förslag som inkluderar lite mer DOM;

```
<style type="text/css">
	#mycontent {
		position:absolute;
		border: solid 1px #000;
		padding: 10px;
		background: #f0f0f0;
		width:600px;
		height:400px;
	}
</style>
<script language="JavaScript" type="text/javascript">
	function center_content() {
		if(document.all){
			document.all["mycontent"].style.left=parseInt((document.body.clientWidth-document.all["mycontent"].offsetWidth)/2);
			document.all["mycontent"].style.top=parseInt((document.body.clientHeight-document.all["mycontent"].offsetHeight)/2);
		} else if(document.layers) {
			document.layers["mycontent"].left=parseInt((window.innerWidth-document["mycontent"].document.width)/2);
			document.layers["mycontent"].top=parseInt((window.innerHeight-document["mycontent"].document.height)/2);
		} else if(document.getElementById&&navigator.appName=="Microsoft Internet Explorer") {
			document.getElementById("mycontent").style.left=parseInt((document.body.clientWidth-document.getElementById("mycontent").offsetWidth)/2);
			document.getElementById("mycontent").style.top=parseInt((document.body.clientHeight-document.getElementById("mycontent").offsetHeight)/2);
		} else if(document.getElementById) {
			document.getElementById("mycontent").style.left=parseInt((window.innerWidth-document.getElementById("mycontent").offsetWidth)/2);
			document.getElementById("mycontent").style.top=parseInt((window.innerHeight-document.getElementById("mycontent").offsetHeight)/2);
		}
	}
</script>
```

Permalänk: https://www.webforum.nu/p/827198

## #3 — Palleman, 2002-10-23T08:31Z

Hmm.. ja det fungerar bra - MEN - lägger jag funktionen i mitt XHTML dokument så fungerar det inte...

Plockar jag bort följande från dokumentet så fungerar det:

\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"DTD/xhtml1-transitional.dtd"\>

Doctypen gör att det buggar ur, vad kan det bero på tror du/ni?

Permalänk: https://www.webforum.nu/p/830529

## #4 — OlleBoop, 2002-10-23T11:21Z

Vilken version av Netscape?
 Plockar du bort DTD:n kommer nyare läsare att gå i "quirks mode", typ att den emulerar vissa buggar från äldre läsare.

Permalänk: https://www.webforum.nu/p/830623

---

Tråden på webben: https://www.webforum.nu/amne/javascript/56417-div-strul-i-netscape
