简体   繁体   English

html输入元素顺序

[英]html input element order

I have 2 labels and 2 radio button , and I want to lay them out as (label radio label radio) 我有2个标签和2个单选按钮,我想将其布局为(标签单选标签radio)

<label>Member</label>
<input type="radio" name="type" value="member" /> 
&nbsp;&nbsp;
<label>Company</label>
<input type="radio" name="type" value="company" />

but I get (label label radio radio )! 但是我得到了(标签标签为radio radio)!
I changed it into <br/> and moved on, but still I want to know what's wrong !!!! 我将其更改为<br/>并继续前进,但我仍然想知道出什么问题了!

update: 更新:
css file contain CSS文件包含

form label { 
display: block;
float: left; 
width: 150px; 
padding: 0; 
margin: 9px 0 0;
text-align: right; }

form input, form select {
margin: 5px 0 0 10px;
padding: 4px;
    float: left; }

I tried for attribute and it worked fine on google chrome& opera but not on IE 我尝试for属性,它在google chrome&Opera上运行良好,但在IE上却无法运行

This can't happen without some CSS applied, probably 如果没有应用某些CSS,这可能不会发生

label { float: left; }

Could you provide a link to the problem or a jsfiddle? 您能否提供问题或jsfiddle的链接?

edit: none of them should float: 编辑:他们都不应该浮动:

label, input[type="radio"] {
  float: static;
}

or all of them: 或全部:

label, input[type="radio"] {
  float: left;
}

but not part of them. 但不是其中的一部分。

Even if my jsfiddle works on Firefox, you should probably try with a for attribute: 即使我的jsfiddle在Firefox上运行,您也应该尝试使用for属性:

<form>
  <label for="Member">Member</label>
  <input type="radio" name="type" id="Member" />
  <br />
  <label for="Company">Company</label>
  <input type="radio" name="type" id="Company" />
</form> 

It probably depends on the web browser you're using, but when I tested your code sample in Firefox on Windows XP, everything looked as expected. 这可能取决于您使用的Web浏览器,但是当我在Windows XP的Firefox中测试代码示例时,一切都按预期进行。

Member o Comoany o

Here's the tricky part, though: Some browsers are more lenient than others in displaying HTML the way we intend versus the way it's supposed to be. 不过,这是棘手的部分:在以我们期望的方式显示HTML的方式上,某些浏览器比其他浏览器更宽容。 I'm sure you're aware of all of that already, but sometimes we run into issues anyway. 我敢肯定您已经意识到所有这些,但是有时候我们还是会遇到问题。

Some things to consider: 要考虑的一些事情:

1) The chosen DOCTYPE which makes some web browsers expect strict adherence to the way we write tags and such. 1)选择的DOCTYPE使某些Web浏览器期望严格遵守我们编写标签等的方式。

2) Sometimes, certain web browsers expect form elements to be within a form. 2)有时,某些Web浏览器期望表单元素位于表单内。

3) A label is typically tied to the corresponding form element. 3)通常将标签绑定到相应的表单元素。 In your case, that would be something like: 在您的情况下,将类似于:

<label for="Member">Member</label>
<input type="radio" name="type" id="Member" value="member" />

4) And the CSS. 4)和CSS。 Are you using a CSS reset file? 您是否正在使用CSS重置文件? In that case, find out what the label CSS is. 在这种情况下,找出标签CSS是什么。 Or write your own label CSS and determine how you want it to be laid out (inline, block, float, etc.) 或编写自己的标签CSS并确定布局的方式(内联,块,浮点等)。

Here's some additional information: http://www.w3schools.com/tags/tag_label.asp 以下是一些其他信息: http : //www.w3schools.com/tags/tag_label.asp

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM