DotNetNuke: Page content centered in FireFox but left aligned in IE

Problem

I have created a custom skin in for DNN that has several div tags centered on the page using the following CSS:

margin: 20px auto 20px auto;

This works great in Firefox, but not in Internet Explorer 7 the same div tags are left aligned.

Firefox

Site Centered

Internet Explorer 7

Site Left Aligned

Solution

I stumbled upon this CSS thread that lead me to believe that this had to do with the default DOCTYPE that DNN uses. I did not see an obvious way to change the DOCTYPE via the admin console. A quick search on Google brought me to this solution posted by John Mitchell.

The issue has to do with the default DOCTYPE that DNN uses. In my case it was:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

The fix that John describes has you add the following code to the skin.ascx file that was created when you imported your custom DotNetNuke skin:

<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Dim skinDocType as Control = Me.Page.FindControl("skinDocType")
   If Not skinDocType is Nothing
      CType(skinDocType, System.Web.UI.WebControls.Literal).Text="<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"
   End If
End Sub
</script>

The above code worked swimmingly for me. Now my site's content is centered in both Firefox and Internet Explorer.

Published Monday, May 07, 2007 12:48 PM by Tod Birdsall

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

IDE@S_Ben said:

Outstanding work Tod! The fix just relieved a headache that even 18 advils, 4 codeines, a couple valiums and a bottle of whiskey couldn't. Appreciate the help, you've got yourself a new subscriber to your blog =)
June 14, 2007 11:10 AM
 

Tod Birdsall said:

Ben,

I am glad it worked for you too. Cross browser CSS can be such a PITA.

June 15, 2007 9:28 AM
 

DNN Newbie said:

Thank you, Thank you, Thank you!  I almost tore apart my site trying to fix this...you're a life saver.  P.S. The skin preview displayed the alignment correctly in IE and Firefox so it was especially frustrating to have a perfectly working skin shown in the preview and then when you apply it to the site, the center alignment is dropped in IE and still maintained in Firefox.

July 8, 2009 11:58 AM
 

DNN Newbie said:

By the way, the skin I'm mentioning above is a pure CSS layout skin developed for DNN 5.1 (just thought I'd mention it in case DNN5 users are encountering this issue with XHTML Strict 1.0 skins in DNN 5.1)

July 8, 2009 12:00 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit
Picture of Tod Birdsall

Welcome!

This is the personal website of Tod Birdsall, a programmer, business analyst, and gamer. Not necessarily in that order. Learn more...

Subscribe

Be notified of my latest posts. Subscribe to my blog.