首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >内联-在IE11中将输入元素换行为新行

内联-在IE11中将输入元素换行为新行
EN

Stack Overflow用户
提问于 2017-04-16 02:50:20
回答 2查看 12.2K关注 0票数 9

在一个用display:inline-flex定位的容器中,我有几个相邻的html元素。

这对于按钮元素很有效,但是只要我尝试添加一个input type="text"元素,文本框就被放在按钮下面(仅在Internet Explorer11中;不确定是否使用IE10或更低版本)。

它在Firefox,Chrome,甚至Edge中都能像预期的那样工作(文本框和按钮在同一行)。

我怎样才能让IE正确地显示它?

查看jsFiddle以获取完整的html和css代码来说明此问题:https://jsfiddle.net/vm2kcwd9/1/

代码语言:javascript
复制
.container {
  height: 2em;
}

.container>* {
  height: 100%;
  display: inline-flex;
  vertical-align: top;
  justify-content: center;
  align-items: center;
}
代码语言:javascript
复制
<div class="container">

  <button>test</button>
  <button>test 2</button>
  <button>test 3</button>
  <input type="text" value="hello" />

</div>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-16 02:57:00

IE11以拥有许多而闻名。

在这种情况下,一种简单的解决方案是将父容器设置为flex容器:

代码语言:javascript
复制
.container {
  display: flex; /* new; forces all children into a single row */
  height: 2em;
}

.container>* {
  height: 100%;
  display: inline-flex;
  /* vertical-align: top; <--- not necessary anymore */
  justify-content: center;
  align-items: center;
  margin: 5px;  /* for demo only */
}
代码语言:javascript
复制
<div class="container">
  <button>test</button>
  <button>test 2</button>
  <button>test 3</button>
  <input type="text" value="hello" />
</div>

此外,由于您要将button元素转换为flex容器,因此请考虑以下内容:

票数 7
EN

Stack Overflow用户

发布于 2017-04-16 02:59:29

简单的解决方案只需将display:flex添加到父级

代码语言:javascript
复制
.container {
  display: flex;
  justify-content: center;
  /* align-items: center; you might not need this */
  height: 2em;
}

.container>* {
  height: 100%;
  margin: 10px;
}
代码语言:javascript
复制
<div class="container">
  <button>test</button>
  <button>test 2</button>
  <button>test 3</button>
  <input type="text" value="hello" />
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43429965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档