2017-08-03 130 views
0

我有两个文本输入似乎不与flex合作。Flex在Firefox中无法正常工作

他们应该被定位是这样的:

enter image description here

..但取而代之的是定位这样的:

enter image description here

CSS

.container{ 
    width: 48.1%; 
    display: -webkit-box; 
    display: -moz-box; 
    display: -ms-flexbox; 
    display: -webkit-flex; 
    display:flex; 
    justify-content: space-between; 
} 

input[type=text] { 
    font-size: 18px; 
    padding: 8px; 
    font-family: 'lato'; 
    font-weight: 300; 
    line-height: 20px; 
    transition: all linear .5s; 
    display: inline; 
    margin-top: 30px; 
    -webkit-appearance: none; 
    -moz-appearance: none; 
    appearance: none; 
    border: 1px solid #ddd; 
} 

#zip{ 
    flex: .21; 
} 

#phone{ 
    flex: .7; 
} 

对于flex:,我使用的是分数,因此它们不会加起来为1,并且应该在对方之间留有一点余量。这只是没有发生。

HTML

<div class="container"> 
    <input type="text" id="zip" name="zip" placeholder="Zip Code" maxlength="5" pattern=".{5,}" oninvalid="setCustomValidity('Please enter a 5-digit zip code')" onchange="try{setCustomValidity('')}catch(e){}" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode == 0" required=""> 
    <input type="text" id="phone" name="phone" placeholder="Phone Number e.g. 888-888-8888" maxlength="12" pattern=".{12,}" oninvalid="setCustomValidity('Please enter a 10-digit phone number')" onchange="try{setCustomValidity('')}catch(e){}" onkeypress="return event.charCode >= 45 &amp;&amp; event.charCode <= 57 || event.charCode == 0" required="">    
</div> 

这似乎在Chrome和Safari的工作,但在Firefox不起作用。

+0

https://stackoverflow.com/q/36247140/3597276 –

回答

2

我发现这是input元素特有的问题。 flex不会在Firefox input元素工作,除非你将其添加到CSS:

input { min-width: 1px; } 
1

这里是这样做的一种方式:

  • 加入align-items:center(有一些height)在.container
  • 加入一些margininputflex:1#phone,一个max-width#zip

.container { 
 
    display: flex; 
 
    justify-content: space-between; 
 
    align-items: center; 
 
    background: red; 
 
    height: 100px 
 
} 
 

 
input[type=text] { 
 
    font-size: 18px; 
 
    padding: 8px; 
 
    font-family: 'lato'; 
 
    font-weight: 300; 
 
    line-height: 20px; 
 
    transition: all linear .5s; 
 
    appearance: none; 
 
    border: 1px solid #ddd; 
 
} 
 

 
input { 
 
    margin: 0 10px 
 
} 
 

 
#zip { 
 
    max-width: 70px 
 
} 
 

 
#phone { 
 
    flex: 1 
 
}
<div class="container"> 
 
    <input type="text" id="zip" name="zip" placeholder="Zip Code" maxlength="5" pattern=".{5,}" oninvalid="setCustomValidity('Please enter a 5-digit zip code')" onchange="try{setCustomValidity('')}catch(e){}" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode == 0" 
 
    required=""> 
 
    <input type="text" id="phone" name="phone" placeholder="Phone Number e.g. 888-888-8888" maxlength="12" pattern=".{12,}" oninvalid="setCustomValidity('Please enter a 10-digit phone number')" onchange="try{setCustomValidity('')}catch(e){}" onkeypress="return event.charCode >= 45 &amp;&amp; event.charCode <= 57 || event.charCode == 0" 
 
    required=""> 
 
</div>

+0

这似乎产生在Firefox相同的结果。这就好像Firefox在忽略'flex:'语句时(当我试用这些语句时我删除了它们) – rpivovar

+0

@coffeebot查看更新后的答案 – dippas

+0

我不想使用空格键,因为我想要项目坐在容器的边缘齐平,并且除了Firefox以外的所有浏览器都可以使用空间。这是Firefox的一个问题,特别是Firefox中的输入。将'min-width'作为属性添加到输入可修复它。 – rpivovar

0

它的工作原理,如果你在使用%宽度,你给盒大小:边界盒;到项目:

.container{ 
 
    width: 48.1%; 
 
    display: -webkit-box; 
 
    display: -moz-box; 
 
    display: -ms-flexbox; 
 
    display: -webkit-flex; 
 
    display:flex; 
 
    justify-content: space-between; 
 
} 
 

 
input[type=text] { 
 
    font-size: 18px; 
 
    padding: 8px; 
 
    font-family: 'lato'; 
 
    font-weight: 300; 
 
    line-height: 20px; 
 
    transition: all linear .5s; 
 
    display: inline; 
 
    margin-top: 30px; 
 
    -webkit-appearance: none; 
 
    -moz-appearance: none; 
 
    appearance: none; 
 
    border: 1px solid #ddd; 
 
    
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
#zip{ 
 
    width: 21%; 
 
} 
 

 
#phone{ 
 
    width: 70%; 
 
}
<div class="container"> 
 
    <input type="text" id="zip" name="zip" placeholder="Zip Code" maxlength="5" pattern=".{5,}" oninvalid="setCustomValidity('Please enter a 5-digit zip code')" onchange="try{setCustomValidity('')}catch(e){}" onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57 || event.charCode == 0" required=""> 
 
    <input type="text" id="phone" name="phone" placeholder="Phone Number e.g. 888-888-8888" maxlength="12" pattern=".{12,}" oninvalid="setCustomValidity('Please enter a 10-digit phone number')" onchange="try{setCustomValidity('')}catch(e){}" onkeypress="return event.charCode >= 45 &amp;&amp; event.charCode <= 57 || event.charCode == 0" required="">    
 
</div>

相关问题