我有一个理解CSS定位的基本问题 [英] I have a basic problem understanding CSS positioning
问题描述
编辑:赏金去任何人可以张贴编辑显示如Delphi截图的HTML。
我使用Borland Delphi生成HTML表单生成器。用户可以拖动&拖放组件生成一个文件,当他很高兴时,他可以生成HTML(我在他的表单末尾弹出一个Submit按钮)。
由于我拥有绝对当我生成每个控件的位置时,我想要在CSS中指定绝对位置。我认为这意味着我必须使用 position:fixed
,但这看起来不正确,绝对也不正确。
我做错了什么? (HTML在W3C验证)
以下是在Delphi程序中设计表单时看到的一个非常基本的基本示例
这里是MSIE 8(与固定位置)
再次以绝对位置
最后,这里是HTML
<!DOCTYPE HTML PUBLIC - // W3C / / DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict.dtd>
< html>
< head>
< title>输入资料< / title>
< meta http-equiv =Content-typecontent =text / html; charset = UTF-8>
< / head>
< body>
< form action =http://localhost/a_submitted.phpmethod =post>
< div class =TGroupBoxid =GroupBox1>
< fieldset style =position:absolute; top:40px; left:40px; width:857px; height:441px;>
<图例> GroupBox1< / legend>
< div class =TPanelid =Panel1>
< fieldset style =position:absolute; top:64px; left:56px; width:753px; height:369px;>
<图例>< /图例>
< div class =TLabelid =Label1style =position:absolute; top:88px; left:80px; width:32px; height:13px;> Label1< / div>
< div class =TEditid =Edit1style =position:absolute; top:80px; left:72px; width:121px; height:21px;>< input type =text name =Edit1value =an edit bx>< / div>
< div class =TCheckBoxid =CheckBox1style =position:absolute; top:88px; left:80px; width:97px; height:17px;> CheckBox1< input type =checkbox name =CheckBox1value =CheckBox1Checked>< / div>
< div class =TComboBoxid =ComboBox1style =position:absolute; top:145px; left:137px; width:145px; height:21px;>
< select size =1name =ComboBox1>
< option value =oneselected =selected> one< / option>
< option value =two> two< / option>
< option value =three> three< / option>
< / select>
< / div>
< div class =TRadioGroupid =RadioGroup1>
< fieldset style =position:absolute; top:144px; left:136px; width:185px; height:105px;>< legend> RadioGroup1< / legend>
red:< input type =radioname =RadioGroup1value =>< br>
white:< input type =radioname =RadioGroup1value =checked>< br>
blue:< input type =radioname =RadioGroup1value =>< br>
< / fieldset>
< / div>
< / fieldset>
< / div>
< / fieldset>
< / div>
< div>< input type =submitname =submitButtonvalue =Submitstyle =position:relative; top:25px; left:50%;>< / div>
< / form>
< / body>
< / html>
编辑:赏金可以发给任何人编辑后的HTML显示如Delphi截图。
编辑:好的,这是有效的。它可能不是正确的,但是1)它正确显示& 2)它在W3C验证。似乎我应该让所有的定位都是绝对的,并且为所有的div添加定位,除了那些带有字段集的字段,我必须将该字段添加到字段集。如果您认为我错了,请随时纠正这一错误,但适用于我!好极了! Yipee!最后!很多+1,并感谢所有帮助。
您可以从以下代码开始。请确保您阅读其他人发布的内容:
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 / /EN\"\"http://www.w3.org/TR/html4/strict.dtd\">
< html>
< head>
< title>输入资料< / title>
< meta http-equiv =Content-typecontent =text / html; charset = UTF-8>
< / head>
< body>
< form action =http://localhost/a_submitted.phpmethod =post>
< div class =TGroupBoxid =GroupBox1>
< fieldset style =>
<图例> GroupBox1< / legend>
< div class =TPanelid =Panel1>
< fieldset style =width:600px; height:250px; margin:20px 50px 50px 20px; padding:20px; padding-left:50px>
< div class =TLabelid =Label1style =position:absolute; left:100px; top:100px;> Label1< / div>
< div class =TEditid =Edit1style =position:absolute; left:200px; top:100px;>< input type =textname =Edit1value = 编辑bx>< / div>
< div class =TCheckBoxid =CheckBox1style =position:absolute; left:400px; top:100px;> CheckBox1< input type =checkboxname =CheckBox1value = CheckBox1Checked >< / DIV>
< div class =TComboBoxid =ComboBox1style =position:absolute; left:100px; top:150px;>
< option value =oneselected =selected> one< / option>
< option value =two> two< / option>
< option value =three> three< / option>
< / select>
< / div>
< div class =TRadioGroupid =RadioGroup1style =position:absolute; left:380px; top:150px;>
< fieldset style =>
< legend> RadioGroup1< / legend>
< input type =radioname =RadioGroup1value =>红色和LT峰; br>
< input type =radioname =RadioGroup1value =checked>白<峰; br>
< input type =radioname =RadioGroup1value =>蓝色<峰; br>
< / fieldset>
< / div>
< / fieldset>
< / div>
< / fieldset>
< / div>
< div>< input type =submitname =submitButtonvalue =Submitstyle =>< / div>
< / form>
< / body>
< / html>
Edit: Ok, this is what works. It may not be "right", but 1) it displays correctly & 2) it validates at W3C. It seems that I should make all positioning absoolute and add positioning to all divs except for those with a fieldset, where I have to add the position to the fieldset. Feel free to correct this if you think that I am wrong, but "it works for me" ! Yay! Yipee! At last! Lots of +1 all round and thanks to all who helped.
Edit: the bounty goes to whomever can post the editted HTML which displays like the Delphi screenshot.
I am using Borland Delphi to produce an HTML form generator. The user can drag & drop components to produce a file and when he is happy he can generate HTML (I pop a Submit button on to the end of his form).
Since I have the absolute position of each control when I am generating, I want so specify absolute positions in CSS. I thought this meant that I have to use position: fixed
, but that doesn't look right, and nor does absolute.
What am I doing wrong? (the HTML validates at W3C)
Here is a very basic basic example as seen when designing the form in the Delphi program
And here it is in MSIE 8 (with fix position)
And again with absolute position
And, finally, here is the HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Input data</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<body>
<form action="http://localhost/a_submitted.php" method="post">
<div class="TGroupBox" id="GroupBox1">
<fieldset style="position: absolute; top:40px; left:40px; width: 857px; height: 441px;">
<legend>GroupBox1</legend>
<div class="TPanel" id="Panel1">
<fieldset style="position: absolute; top:64px; left:56px; width: 753px; height: 369px;">
<legend></legend>
<div class="TLabel" id="Label1" style="position: absolute; top:88px; left: 80px; width: 32px; height: 13px;">Label1</div>
<div class="TEdit" id="Edit1" style="position: absolute; top:80px; left: 72px; width: 121px; height: 21px;"><input type="text" name="Edit1" value="an edit bx"></div>
<div class="TCheckBox" id="CheckBox1" style="position: absolute; top:88px; left: 80px; width: 97px; height: 17px;">CheckBox1<input type="checkbox" name="CheckBox1" value="CheckBox1Checked"></div>
<div class="TComboBox" id="ComboBox1" style="position: absolute; top:145px; left: 137px; width: 145px; height: 21px;">
<select size ="1" name="ComboBox1">
<option value="one" selected="selected">one </option>
<option value="two">two </option>
<option value="three">three </option>
</select>
</div>
<div class="TRadioGroup" id="RadioGroup1">
<fieldset style="position: absolute; top:144px; left: 136px; width: 185px; height: 105px;"><legend>RadioGroup1</legend>
red: <input type="radio" name="RadioGroup1" value=""><br>
white: <input type="radio" name="RadioGroup1" value="" checked><br>
blue: <input type="radio" name="RadioGroup1" value=""><br>
</fieldset>
</div>
</fieldset>
</div>
</fieldset>
</div>
<div><input type="submit" name="submitButton" value="Submit" style="position:relative; top:25px; left: 50%;"></div>
</form>
</body>
</html>
Edit: the bounty goes to whomever can post the editted HTML which displays like the Delphi screenshot.
Edit: Ok, this is what works. It may not be "right", but 1) it displays correctly & 2) it validates at W3C. It seems that I should make all positioning absoolute and add positioning to all divs except for those with a fieldset, where I have to add the position to the fieldset. Feel free to correct this if you think that I am wrong, but "it works for me" ! Yay! Yipee! At last! Lots of +1 all round and thanks to all who helped.
You can start with the following code. Make sure you read what others have posted:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Input data</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<body>
<form action="http://localhost/a_submitted.php" method="post">
<div class="TGroupBox" id="GroupBox1">
<fieldset style="">
<legend>GroupBox1</legend>
<div class="TPanel" id="Panel1">
<fieldset style="width: 600px; height: 250px; margin: 20px 50px 50px 20px; padding: 20px; padding-left: 50px">
<div class="TLabel" id="Label1" style="position: absolute; left: 100px; top: 100px;">Label1</div>
<div class="TEdit" id="Edit1" style="position: absolute; left: 200px; top: 100px;"><input type="text" name="Edit1" value="an edit bx"></div>
<div class="TCheckBox" id="CheckBox1" style="position: absolute; left: 400px; top: 100px;">CheckBox1 <input type="checkbox" name="CheckBox1" value="CheckBox1Checked"></div>
<div class="TComboBox" id="ComboBox1" style="position: absolute; left: 100px; top: 150px;">
<select size ="1" name="ComboBox1" style="width: 200px;">
<option value="one" selected="selected">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
</div>
<div class="TRadioGroup" id="RadioGroup1" style="position: absolute; left: 380px; top: 150px;">
<fieldset style="">
<legend>RadioGroup1</legend>
<input type="radio" name="RadioGroup1" value=""> red<br>
<input type="radio" name="RadioGroup1" value="" checked> white<br>
<input type="radio" name="RadioGroup1" value=""> blue<br>
</fieldset>
</div>
</fieldset>
</div>
</fieldset>
</div>
<div><input type="submit" name="submitButton" value="Submit" style=""></div>
</form>
</body>
</html>
这篇关于我有一个理解CSS定位的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!