简体   繁体   English

我的输入字段在IE上以内联方式呈现,但在Chrome和Firefox中以换行方式呈现。 我该如何解决?

[英]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中完全不同: GUI错误

JSFiddle link JSFiddle链接

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

DEMO HERE 此处演示

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;
}   

And JSFiddle JSFiddle

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.

相关问题 用于渲染图像的ASPX页面突然无法在Firefox中运行。 适用于Chrome / IE - ASPX page to render image suddenly not working in Firefox. Works in Chrome/IE 视差滚动动画在IE浏览器中黯然失色,在Chrome和Firefox中流畅。 我的代码或IE问题? - Parallax Scroll Animation Choppy in IE, Yet Smooth in Chrome and Firefox. Issue with my code, or IE? 如何为Mozilla Firefox优化网页? 我的页面在Firefox上无法正确显示。 镀铬,完美 - How to optimize web pages for Mozilla Firefox? My pages are not displaying correctly on firefox. In chrome, it's perfect 如何在Chrome上显示的Firefox输入字段之间获得空间? - How do i get space between my input fields in Firefox that appear on Chrome? 如何获取IE,Firefox,Chrome以使输入文本框一致? - How can i get IE, Firefox, Chrome to align input textbox the same? 为什么我的Ajax不能在Google Chrome或IE上运行,而在FireFox上运行,又如何使它工作? - Why Does my Ajax Not work on Google Chrome Or IE but works on FireFox, And how can i make it work 文本输入未在Firefox中显示。 - Text input not showing in Firefox. 组合框 alignment 在铬和 firefox 中失败。 问题似乎与 style.display = “inline”有关。寻找解决方案 - Combo-box alignment failing in chrome and firefox. The issue seems with style.display = “inline”.Looking for a solution 我为订阅表单编写了一个样式。 它在firefox中看起来不错。 但是歌剧中的风格看起来并不相似。 怎么解决? - I write a style for a subscribe form. It's looks good in firefox. But style is not looking similar in opera. How to fix it? 如何解决Firefox中的跨度/格问题(在IE中按需显示)以及如何调整Chrome中的未对准? - How do I fix span/div issues in Firefox (displays as wanted in IE) and adjust misalignment in Chrome?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM