Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

CSS,ASP.NET: Correctly positioning divs without DOCTYPE

Hello everyone,

I am working on a website that doesn't use DOCTYPE. I am trying to position a div but it doesn't show up correctly unless I put the DOCTYPE instruction on the top of the page markup. I there a way I can make this work without using the DOCTYPE?
P.S: I use tables to position my content.
0
karakav
Asked:
karakav
  • 8
  • 8
1 Solution
 
amazingwolf1Commented:
Can you post your html code?
0
 
karakavAuthor Commented:
Here you are
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat="server">
    <title>Test Page</title>
 
    <script language="javascript" type="text/javascript">
        function showHide() 
        {                
            var theDiv = document.getElementById("mainDiv");     
            if(theDiv.style.visibility == "visible" || theDiv.style.visibility == "")      
            {
                theDiv.style.visibility = "hidden";           
            }
            else                 
            {
                theDiv.style.visibility = "visible";       
            }                               
        }              
    </script>
 
    <style type="text/css">    
        #mainDiv
        {
	        position: fixed;
	        top: 0;
	        left: 0;        	
	        background-color:#666;
	        filter:alpha(opacity=80); 
	        opacity:0.8;         	
	        height: 100%;
	        width: 100%;
	        min-height: 100%; 
	        min-width: 100%;
	        z-index:1;         
        }
        #innerDiv
        {
	        background-color: #ffff99;
	        color: black;
	        width: 50%;
	        text-align: center;
	        vertical-align: middle;
	        position: fixed;
	        bottom: 50%;
	        left: 25%;
	        font-weight:bold;
	        z-index:2; 
        }    
</style>
</head>
<body onload="showHide();">
    <form id="form1" runat="server" onsubmit="showHide();">
        <div id="mainDiv">
            <div id="innerDiv">
                            <asp:Label ID="label1" runat="server" >Please wait ...</asp:Label>
            </div>
        </div>
        <table>
            <tr>
                <td>
                    <asp:Button ID="button1" runat="server" Text="Ici"
                        OnClick="button1_Click" />
                    <asp:DropDownList ID="drop" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drop_SelectedIndexChanged">
                        <asp:ListItem Text="Valor 1" Value="1" Selected="True" />
                        <asp:ListItem Text="Valor 2" Value="2" />
                        <asp:ListItem Text="Valor 3" Value="3" />
                    </asp:DropDownList>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
 
 
 
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
 
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void button1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(2000);
    }
    protected void drop_SelectedIndexChanged(object sender, EventArgs e)
    {
        Thread.Sleep(3000);
    }
}

Open in new window

0
 
amazingwolf1Commented:
Does this help?
<body onload="showHide();" style="margin-left:5px;margin-top:0px">
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
karakavAuthor Commented:
No it doesn't.
0
 
amazingwolf1Commented:
Oh, ok, got you. change position: absolute; in the style of mainDiv and innerDiv - then it will work.
0
 
karakavAuthor Commented:
It doesn't fit completely the window. Check on the right side.
0
 
amazingwolf1Commented:
Add this to the style section:

 body {
      margin-left: 0px;
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
}
0
 
karakavAuthor Commented:
Sorry for the delay. I can't defiine those values in the Body selector because I may need to define different values depending on the page. I was looking for  a solution that only affect the divs.
0
 
amazingwolf1Commented:
The div is effected by the size of the body of the page. You can generate the body style programatically. I don't think there is such a solution that ignores the state of the body, since it is your "canvas", sort of speak.

0
 
karakavAuthor Commented:
Even like that the div is not covering all the window especially still on the right side.
0
 
amazingwolf1Commented:
ok - which browser do you use?
0
 
karakavAuthor Commented:
I use Internet explorer 7. When I put on six, it is even worse because the dropdownlist overlap the div.
0
 
amazingwolf1Commented:
I have an IE 7.0 and it seems ok...?
Hmmmm... The ghosts start to appear.

I will try and check this on IE 6.0 for you, but it make take me some time. Since IE versions behave differently with HTML, and since DOCTYPE is out of the question, this one will be a bit tricky.
0
 
karakavAuthor Commented:
No proble. I will wait. Thanks.
0
 
amazingwolf1Commented:
Hi
I checked both on IE 7.0 and 6.0 and can't seem to see a probelm...
This is very strange, I am sorry but since I cannot reproduce this I think you should try and play with the code a bit to find what twicks are needed there.

Sorry for the delay, hope you'd find the rest of the solution.
0
 
karakavAuthor Commented:
Actually it is not possible, at least to my possibilities, to correctly imitate whot DOCTYPE make the browsers do. For the problem of dropdowlist in IE6 I had to use an iframe to solve that but even though many other problems are coming in. Thanks for your cooperation anyway.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now