/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Cross Brower Compatibility

Some time ago I had a JavaScript code, which compensated for the visitor’s browser type ie. Opera, Firefox or IE. I’ve lost that script and can’t seem to author a new one, so here I am.

The following “code” when viewed in IE, is left justified and when viewed in Opera, it is centered, like I intended it to be.

Is there a routine that anyone may know of to correct this problem?

The coded page:

[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>

<head>

<style type=”text/css”>
<!–

/* style.css – a simple style sheet */
#container {
width: 766px;
margin: 0 auto;
padding: 0;
}

#header-01 {
width: 730px;
height: 100px;
margin: 0 0 2px 0;
border: 1px solid green;
font-weight: normal;
background-color: #ffd;
padding: 5px;
}

#navigation {
float: left;
width: 150px;
height: 300px;
margin: 2px 2px 2px 0;
border: 1px solid red;
font-weight: normal;
background-color: #fdf;
padding: 5px;
}

#content-01 {
float: left;
width: 422px;
height: 300px;
margin: 2px;
border: 1px solid blue;
font-weight: normal;
background-color: #dff;
padding: 5px;
}

#content-02 {
float: left;
width: 150px;
height: 300px;
margin: 2px 0 2px 2px;
border: 1px solid gold;
font-weight: normal;
background-color: #efe;
padding: 5px;
}

#footer {
clear: both;
width: 730px;
height: 100px;
margin: 0 0 2px 0;
border: 1px solid purple;
font-weight: normal;
background-color: #eef;
padding: 5px;
}

–>
</style>

</head>
<body>
<div id=”container”>
<div id=”header-01″>
<h2>Header</h2>
</div>
<div id=”navigation”>
<ul>
<p>Navigation</p>
</ul>
</div>
<div id=”content-01″>
<p>Content-01</p>
</div>
<div id=”content-02″>
<p>Content-02</p>
</div>
<div id=”footer”>
<p>Footer</p>
</div>
</div> <!– container –>
</body>
</html>[/CODE]

Thanks in advance for your time, knowledge and understanding!

Regards,

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@zyghMar 21.2006 — couldn't u just add..
<i>
</i>text-align:center;


to each of the id selectors?
Copy linkTweet thisAlerts:
@UltimaterMar 21.2006 — Almost exactly as Zygh sugested, is my own suggestion.
<i>
</i>body{text-align:center;}

Then nest another DIV within the main container DIV and set that one to text-align:left;

In otherwords:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;html&gt;

&lt;head&gt;

&lt;style type="text/css"&gt;
&lt;!--
body{text-align:center}

/* style.css - a simple style sheet */
#container {
width: 766px;
margin: 0 auto;
padding: 0;
}

#header-01 {
width: 730px;
height: 100px;
margin: 0 0 2px 0;
border: 1px solid green;
font-weight: normal;
background-color: #ffd;
padding: 5px;
}

#navigation {
float: left;
width: 150px;
height: 300px;
margin: 2px 2px 2px 0;
border: 1px solid red;
font-weight: normal;
background-color: #fdf;
padding: 5px;
}

#content-01 {
float: left;
width: 422px;
height: 300px;
margin: 2px;
border: 1px solid blue;
font-weight: normal;
background-color: #dff;
padding: 5px;
}

#content-02 {
float: left;
width: 150px;
height: 300px;
margin: 2px 0 2px 2px;
border: 1px solid gold;
font-weight: normal;
background-color: #efe;
padding: 5px;
}

#footer {
clear: both;
width: 730px;
height: 100px;
margin: 0 0 2px 0;
border: 1px solid purple;
font-weight: normal;
background-color: #eef;
padding: 5px;
}

--&gt;
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div id="container"&gt;
&lt;div style="text-align:left"&gt;
&lt;div id="header-01"&gt;
&lt;h2&gt;Header&lt;/h2&gt;
&lt;/div&gt;
&lt;div id="navigation"&gt;
&lt;ul&gt;
&lt;p&gt;Navigation&lt;/p&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id="content-01"&gt;
&lt;p&gt;Content-01&lt;/p&gt;
&lt;/div&gt;
&lt;div id="content-02"&gt;
&lt;p&gt;Content-02&lt;/p&gt;
&lt;/div&gt;
&lt;div id="footer"&gt;
&lt;p&gt;Footer&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt; &lt;!-- container --&gt;
&lt;/body&gt;
&lt;/html&gt;

This should make IE and Opera render it the same. However Firefox still needs work because "Content-02" is rendered a little too wide. There is a Firefox screenshot at the bottom of this post. Firefox wants a width of 126 while opera and IE want a width of 150. I'm not very good with CSS, but the CSS forum should be of help.

Firefox screenshot after applying my changes:

[upl-file uuid=8c40f2cd-0bdd-4be6-bf33-bc5871a821b9 size=28kB]Firefox_screenshot.JPG[/upl-file]
Copy linkTweet thisAlerts:
@BytesauthorMar 21.2006 — OK &#8211; Here&#8217;s what I get!

Zygh, when I try your posting, the text in each section is centered, but the overall page is still &#8220;left justified&#8221; when viewed in the IE browser.

Ultimater, It&#8217;s getting better, in IE the page is centered (somewhat better, but not all sections are aligned properly) and the text within the different sections is also &#8220;centered&#8221;, just like Zygh aforementioned posting.

Implementing, your helpful suggestions creates an additional problem, in that; any text that will be entered into the different sections will all be &#8220;centered&#8221;, which is not a necessarily desired concern.

Thanks folks, and lets keep thinking.
Copy linkTweet thisAlerts:
@BytesauthorMar 21.2006 — Ultimater, I screwed up copying your code!

[B]Your code works perfectly[/B]

I really wish there was JavaScript routine that was a solve all solution to most of the compatibility issues. I understand it can't be a solve-all-solution, like the old K-Mart days, but it would be nice!

[B]Thanks Guys[/B]
×

Success!

Help @Bytes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...