[英]My input fields render inline on IE, but on new lines in Chrome and Firefox. How can I fix that?
What do I need to change to make Chrome and Firefox render the same way as Internet Explorer? 要使Chrome和Firefox呈现与Internet Explorer相同的方式,我需要更改什么? My first idea was to use CSS calc()
, but I still need to support IE8. 我的第一个想法是使用CSS calc()
,但我仍然需要支持IE8。
I have the following CSS: 我有以下CSS:
* {
box-sizing: border-box;
}
.Width300
{
width: 300px;
padding: 5px;
border: black 1px solid;
}
.Field
{
white-space: nowrap;
min-height: 26px;
padding: 1px 0;
}
label
{
float: left;
display: inline;
}
input
{
display: block;
width: 100%;
}
.LabelSize100 .Field
{
margin-right: 100px;
}
.LabelSize100 label
{
width: 100px;
}
.LabelSize100 input
{
margin-left: 100px;
}
and the following HTML: 以及以下HTML:
<div class="LabelSize100 Width300">
<div class="Field">
<label>test:</label>
<input type="text" />
</div>
<div class="Field">
<label>test:</label>
<input type="text" />
</div>
</div>
and the result is totally different in IE/Chrome and FF: 结果在IE / Chrome和FF中完全不同:
Just set display:inline-block;
只需设置display:inline-block;
to <label>
and <input>
到<label>
和<input>
CSS 的CSS
label
{
float: left;
display: inline-block;
}
input
{
display: inline-block;
width: 100%;
}
.LabelSize100 input
{
// Remove margin-left
}
Note: remove margin-left
from <input>
注意:从<input>
删除margin-left
距
I got this solution: 我得到了这个解决方案:
HTML: HTML:
<div class="LabelSize100 Width300">
<div class="Field">
<label>test:</label>
<input type="text" />
</div>
<div class="Field">
<label>test:</label>
<input type="text" />
</div>
</div>
CSS: CSS:
* {
box-sizing: border-box;
}
.Width300 {
width: 300px;
padding: 5px;
border: black 1px solid;
}
.Field {
white-space: nowrap;
min-height: 26px;
padding: 1px 0;
width:100%;
}
label {
float: left;
}
input {
display: block;
float:right;
}
.LabelSize100 .Field {
margin-right: 100px;
overflow: hidden;
}
.LabelSize100 label {
width: 100px;
}
Seems to work on all 3 browsers 似乎可以在所有3种浏览器上使用
You have an error in your syntax, look at class `.Field 您的语法有误,请查看类`.Field
{
white-space: nowrap;
min-height: 26px;
padding: 1px 0;.Field
}
.Field
should not be after padding
.Field
不应在padding
后
Is this what you're looking for? 这是您要找的东西吗?
* { box-sizing: border-box; } .Width300 { width: 300px; padding: 5px; border: black 1px solid; } .Field { white-space: nowrap; min-height: 26px; padding: 1px 0; } label { float: left; display: inline; } input { display: inline-block; width: 100%; } .LabelSize100 .Field { margin-right: 100px; } .LabelSize100 label { width: 100px; } .LabelSize100 input { margin-left: 0px; }
<div class="LabelSize100 Width300"> <div class="Field"> <label>test:</label> <input type="text" /> </div> <div class="Field"> <label>test:</label> <input type="text" /> </div> </div>
You should include a normalize CSS file. 您应该包括一个规范化的CSS文件。 It's a file that makes browsers render all elements more consistently and in line with modern standards. 这个文件可以使浏览器更一致地呈现所有元素,并符合现代标准。 Download this file and include it before your CSS: http://necolas.github.io/normalize.css/ 下载此文件并将其包含在CSS之前: http : //necolas.github.io/normalize.css/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.