HTML inputs ignore flex-basis CSS property [duplicate]

六眼飞鱼酱① 提交于 2020-01-11 10:33:29

问题


Somewhy inputs do not perceive flex-basis correctly. Here is a simplest example illustrating how inputs do not obey and span outside of their parent block (see jsfiddle):

<div>
    <input>
    <input>
</div>

<style>     
    div { display: flex; width: 200px; border: 2px solid red; }
    input { flex-basis: 50%; }
</style>

Here is another, more comprehensive, case.

What the hell? :)


回答1:


The input elements has an instrinsic width - and width of flex items (along the flex axis) default to auto. Reset this using min-width: 0 - see demo below:

div {
  display: flex;
  width: 200px;
  border: 2px solid red;
}

input {
  flex-basis: 50%;
  min-width: 0; /* ADDED */
}
<div>
  <input>
  <input>
</div>


来源:https://stackoverflow.com/questions/46684636/html-inputs-ignore-flex-basis-css-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!