View Full Version : position stuff inside a div
Vermelh0
08-30-2002, 12:04 AM
Ok, I have 2 divs on my page. One centers the first one and the second behaves like a panel showing all my controls and stuff. My problems lies in how to contering stuff inside the first div vertically. Centering horizontally is no problem, as I can use the text-center style, but I'm drawing a blank on to center the second div vertically.
Thanks,
V
Quiet Storm
08-30-2002, 01:24 AM
I think the only way is with padding:
<style type="text/css">
p {padding: 20px 3px 3px 20px}
</style>
Vermelh0
08-30-2002, 01:33 AM
Doesn't your solution just move the second div down 20px? This doesn't compensate for different resolutions, right???? So, the div would still not be vertically centered aligned....
V
boxer_1
08-30-2002, 01:46 AM
I'm not 100% on this, but you might be able to use:
padding: 50%;
Any help?
Quiet Storm
08-30-2002, 01:58 AM
Doesn't seem to work right...
Testing different ideas here:
http://www.w3schools.com/css/tryit.asp?filename=trycss_padding-top
boxer_1
08-30-2002, 02:07 AM
Originally posted by Quiet Storm
Doesn't seem to work right...
Testing different ideas here:
http://www.w3schools.com/css/tryit.asp?filename=trycss_padding-top
Hmm..."padding-top: 50%; seems to come close, but apparently not the correct solution as it still doesn't appear to be centered vertically :confused: .
joh6nn
08-30-2002, 02:23 AM
can we see the code for this? 'cause i think i have an easy answer for this, but it depends on whether or not the assumptions i'm making are correct.
'cause as i see it, if the one div is inside the other, you could just position it.
Vermelh0
08-30-2002, 09:34 PM
ok Here's a portion of my sample test page. I thought about vertical positioning the div, but I want to do this on other forms, which could have an infinite number of controls, so that I can't guarantee the size of the inner div.
Here you go... Just pasting this into the body tags of an html page should allow you to see the effect I'm trying to accomplish.
<DIV style="TEXT-ALIGN: center">
<DIV style="BORDER-RIGHT: thin outset; BORDER-TOP: thin outset; Z-INDEX: 101; BORDER-LEFT: thin outset; WIDTH: 407px; BORDER-BOTTOM: thin outset; POSITION: relative; HEIGHT: 235px; BACKGROUND-COLOR: lightgrey" ms_positioning="GridLayout">
<input name="m_TextBox" type="text" value="10" maxlength="10" id="m_TextBox" onselect="setCaretPos(this);" onkeyup="setCaretPos(this);" onclick="setCaretPos(this);" onblur="return validateInput(this, event)" onkeypress="return checkInput(this, event)" maxvalue="32767" minvalue="0" nrtype="Integer" style="Z-INDEX:108;LEFT:20px;POSITION:absolute;TOP:15px;background-color:#e9efff;text-align:right;" /><input name="m_TextBox2" type="text" value="55" maxlength="5" readonly="readonly" id="m_TextBox2" disabled="disabled" style="Z-INDEX:104;LEFT:20px;POSITION:absolute;TOP:51px;background-color:#d7dcd2;text-align:right;" /><input name="m_TextBox3" type="text" value="10.00000" maxlength="10" id="m_TextBox3" onselect="setCaretPos(this);" onkeyup="setCaretPos(this);" onclick="setCaretPos(this);" onblur="return validateInput(this, event)" casasrepr="3" tiporound="TYP_UPPER" maxvalue="99999.99999" onkeypress="return checkInput(this, event)" minvalue="0" nrtype="Double" casasdec="5" style="Z-INDEX:102;LEFT:20px;POSITION:absolute;TOP:86px;background-color:#e9efff;text-align:right;" />
<input name="m_TextBox4" type="text" value="10.000" maxlength="10" id="m_TextBox4" style="Z-INDEX:103;LEFT:20px;POSITION:absolute;TOP:119px;background-color:#e9efff;text-align:right;" />
<input name="m_TextBox5" type="text" maxlength="5" id="m_TextBox5" style="Z-INDEX:101;LEFT:20px;POSITION:absolute;TOP:151px;background-color:white;text-align:left;" />
<input name="m_TextBox6" type="text" value="10" maxlength="10" id="m_TextBox6" style="Z-INDEX:105;LEFT:20px;POSITION:absolute;TOP:188px;background-color:#e9efff;text-align:right;" /><input type="submit" name="Button1" value="Button" id="Button1" style="Z-INDEX: 106; LEFT: 317px; POSITION: absolute; TOP: 15px" />
<input name="TextBox1" type="text" id="TextBox1" onblur="ConfirmDialog('Do you want to continue?');" style="Z-INDEX: 107; LEFT: 219px; POSITION: absolute; TOP: 51px" />
<DIV style="BORDER-RIGHT: thin groove; BORDER-TOP: thin groove; Z-INDEX: 110; LEFT: 238px; BORDER-LEFT: thin groove; WIDTH: 137px; BORDER-BOTTOM: thin groove; POSITION: absolute; TOP: 86px; HEIGHT: 100px" ms_positioning="GridLayout">
<table id="RadioButtonList1" border="0" style="Z-INDEX: 109; LEFT: 26px; POSITION: absolute; TOP: 20px">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_0">Radio 1</label></td>
</tr><tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_1">Radio 2</label></td>
</tr>
</table></DIV>
</DIV>
</DIV>
Vermelh0
08-30-2002, 09:48 PM
Strange, I tried pasting my code into the link above "http://www.w3schools.com/css/tryit.asp?filename=trycss_padding-top", but the right controls are all misaligned. Why is that????
V
adios
08-31-2002, 03:35 AM
Vertical centering within the CSS2 box model seems to generate endless discussions; typical:
http://www.google.com/search?q=+site:lists.w3.org+css+vertical+center&hl=en&lr=&ie=UTF-8&oe=UTF-8&start=0&sa=N
http://www.milov.nl/forum/1/28
Should be easy (like text-align). Here's a simple JS solution:
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function getElement(id) {
return document.getElementById ? document.getElementById(id) :
document.all ? document.all(id) : null;
}
function getClientWidth() {
return document.body && document.body.clientWidth ? document.body.clientWidth :
window.innerWidth ? innerWidth : null;
}
function getClientHeight() {
return document.body && document.body.clientHeight ? document.body.clientHeight :
window.innerHeight ? innerHeight : null;
}
function client_center(id) {
var el = getElement(id);
if (el && el.offsetWidth)
el.style.left = String(getClientWidth()/2 - el.offsetWidth/2 + 'px');
el.style.top = String(getClientHeight()/2 - el.offsetHeight/2 + 'px');
}
function show() {
for (var a=0; a<arguments.length; ++a) {
var el = getElement(arguments[a]);
if (el && el.style) el.style.visibility = 'visible';
}
}
onload = function() {
client_center('controls');
show('controls');
}
</script>
</head>
<body>
<DIV id="controls" style="BORDER-RIGHT: thin outset; BORDER-TOP: thin outset; Z-INDEX: 101; BORDER-LEFT: thin outset; WIDTH: 407px; BORDER-BOTTOM: thin outset; POSITION: absolute; HEIGHT: 235px; BACKGROUND-COLOR: lightgrey;visibility:hidden;" ms_positioning="GridLayout">
<input name="m_TextBox" type="text" value="10" maxlength="10" id="m_TextBox" onselect="setCaretPos(this);" onkeyup="setCaretPos(this);" onclick="setCaretPos(this);" onblur="return validateInput(this, event)" onkeypress="return checkInput(this, event)" maxvalue="32767" minvalue="0" nrtype="Integer" style="Z- INDEX:108;LEFT:20px;POSITION:absolute;TOP:15px;background-color:#e9efff;text-align:right;" /><input name="m_TextBox2" type="text" value="55" maxlength="5" readonly="readonly" id="m_TextBox2" disabled="disabled" style="Z- INDEX:104;LEFT:20px;POSITION:absolute;TOP:51px;background-color:#d7dcd2;text-align:right;" /><input name="m_TextBox3" type="text" value="10.00000" maxlength="10" id="m_TextBox3" onselect="setCaretPos(this);" onkeyup="setCaretPos(this);" onclick="setCaretPos(this);" onblur="return validateInput(this, event)" casasrepr="3" tiporound="TYP_UPPER" maxvalue="99999.99999" onkeypress="return checkInput(this, event)" minvalue="0" nrtype="Double" casasdec="5" style="Z- INDEX:102;LEFT:20px;POSITION:absolute;TOP:86px;background-color:#e9efff;text-align:right;" />
<input name="m_TextBox4" type="text" value="10.000" maxlength="10" id="m_TextBox4" style="Z- INDEX:103;LEFT:20px;POSITION:absolute;TOP:119px;background-color:#e9efff;text-align:right;" />
<input name="m_TextBox5" type="text" maxlength="5" id="m_TextBox5" style="Z- INDEX:101;LEFT:20px;POSITION:absolute;TOP:151px;background-color:white;text-align:left;" />
<input name="m_TextBox6" type="text" value="10" maxlength="10" id="m_TextBox6" style="Z- INDEX:105;LEFT:20px;POSITION:absolute;TOP:188px;background-color:#e9efff;text-align:right;" /><input type="submit" name="Button1" value="Button" id="Button1" style="Z-INDEX: 106; LEFT: 317px; POSITION: absolute; TOP: 15px" />
<input name="TextBox1" type="text" id="TextBox1" onblur="ConfirmDialog('Do you want to continue?');" style="Z-INDEX: 107; LEFT: 219px; POSITION: absolute; TOP: 51px" />
<DIV style="BORDER-RIGHT: thin groove; BORDER-TOP: thin groove; Z-INDEX: 110; LEFT: 238px; BORDER-LEFT: thin groove; WIDTH: 137px; BORDER-BOTTOM: thin groove; POSITION: absolute; TOP: 86px; HEIGHT: 100px" ms_positioning="GridLayout">
<table id="RadioButtonList1" border="0" style="Z-INDEX: 109; LEFT: 26px; POSITION: absolute; TOP: 20px">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_0">Radio 1</label></td>
</tr><tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_1">Radio 2</label></td>
</tr>
</table>
</DIV>
</DIV>
</body>
</html>
joh6nn
08-31-2002, 04:21 AM
maybe i'm just missing something, but that sample code seems to be working fine for me. moz1.1, win98
Vermelh0
08-31-2002, 03:23 PM
joh6nn, you're right.... The sample code was fine, but I left out the following css code in the sample page, and that was throwing off the radio buttons position.
<style type="text/css">
td {padding-top: 2cm}
</style>
Adios,
"http://milov.nl/code/css/verticalcenter.html "
This link seems to be just what I want. Now I need to check, if I can convert my divs into something similar. Should be easy enough to discover. Thanks for the help everyone.
V
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.