Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Centered Login Box

Posted on 2008-06-25
7
1,105 Views
Last Modified: 2013-11-19
I want to have a login box appear in the center of the screen.
I have a header fixed to the top of the window and a footer fixed to the bottom.
I want my login to float in the center of the window.
The attached code works, BUT
1. I can only get it working in HTML 3.2 not XHTML with CSS.
2. I don't think I should need to use a table to do layout.

<?xml version="1.0" ?>
<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">    
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>Login</title>
<style type='text/css'>
label {
        float: left;
        width: 5em;
}
input {
        display: block;
}
fieldset {
        width: 25em;
}
table {
        width: 100%;
        height: 100%;
}
td {
        vertical-align: middle;
}
#header {
        position: absolute;
}
#footer {
        position: absolute;
        bottom: 0px;
}
#content {
        vertical-align: middle;
}
</style>
</head>
<body>
<div id='header'>
<h1>Heading</h1>
</div>
<div id='content'>
<table><tr><td valign='middle' align='center'>
<form id='loginform' action='/login.php'>
<fieldset>
<legend>Please identify yourself</legend>
<label for='user'>Username:</label>
<input type='text' name='user' id='user'/>
<label for='pass'>Password:</label>
<input type='password' name='pass' id='pass'/>
<label for='login'></label>
<input type='submit' name='login' id='login' value='Login' />
</fieldset>
</form>
</td></tr></table>
</div>
<div id='footer'>
<p>Copyright &copy;</p>
</div>
</body>
</html>

Open in new window

0
Comment
Question by:bevhost
  • 5
7 Comments
 
LVL 11

Accepted Solution

by:
asafadis earned 300 total points
ID: 21864526
0
 
LVL 19

Author Comment

by:bevhost
ID: 21864885
That solution works for a know height, but it doesn't work with an unknown height.
Look at these in a web browser and you will see what I mean.
Resize the browser window and watch the effect.
0
 
LVL 19

Author Comment

by:bevhost
ID: 21865058
see attached screenshots
sampleLogin.jpg
sampleLoginBigger.jpg
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 42

Assisted Solution

by:David S.
David S. earned 200 total points
ID: 21871485
> That solution works for a know height, but it doesn't work with an unknown height.

A known height of which element? I've used that technique several times. That technique is tricky though. I expect you missed a step or put in an extra element that interfered with it. Please show us the code for your try at using it.

By the way, the XML declaration (the line above the doctype) forces IE6 into quirks mode, which is usually a bad thing. (They fixed that bug in IE7.) I suggest you remove it.
0
 
LVL 19

Author Comment

by:bevhost
ID: 21872205
Kravimir, I was referring to the solution suggested by asafadis
The browser window is an unknown height.  
The elements on the page are also unknown size depending on the zoom and text size.

The solution provided at http://www.jakpsatweb.cz/css/css-vertical-center-solution.html places text in the middle of a table which has a fixed height.  I want to place my login box in the middle of the web browser window, which in my example is in a table set to height=100%.

This works properly when the DOCTYPE is set to HTML 3.2 but I just don't know what the right way to do this is when the DOCTYPE is set to XHTML.
0
 
LVL 19

Author Comment

by:bevhost
ID: 21872315
I've had a closer look at that solution and it does work for me.
I even understand how it works.  very nice.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" >
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>Login</title>
<style type='text/css'>
label {
	float: left;
	width: 5em;
}
input {
	display: block;
}
fieldset {
	width: 25em;
	position: relative;
	top: -50px;
	margin-right: auto;
	margin-left: auto;
}
#header {
	position: absolute;
}
#footer {
	position: absolute;
	bottom: 0px;
}
#content {
	position: absolute;
	top: 50%;
	display: table-cell;
	vertical-align: middle;
}
</style>
</head>
<body>
<div id='header'>
<h1>Heading</h1>
</div>
<div id='content'>
<form id='loginform' action='/login.php'>
<fieldset>
<legend>Please identify yourself</legend>
<label for='user'>Username:</label>
<input type='text' name='user' id='user'/>
<label for='pass'>Password:</label>
<input type='password' name='pass' id='pass'/>
<label for='login'></label>
<input type='submit' name='login' id='login' value='Login' />
</fieldset>
</form>
</div>
<div id='footer'>
<p>Copyright &copy;</p>
</div>
</body>
</html>

Open in new window

0
 
LVL 19

Author Closing Comment

by:bevhost
ID: 31470494
I didn't understand the example properly the first time,  as it was sitting inside a fixed sized container.
But I get it now.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question