简体   繁体   English

如何在一行中水平对齐表单域?

[英]How do I align the form fields horizontally in one line?

I am trying to align and resize the form fields in the link attached horizontally and in one line. 我试图在水平和一行连接的链接中对齐和调整表单字段的大小。 Any ideas on how I could ? 关于我如何有任何想法?

https://beyondcondo.com/testpage/ https://beyondcondo.com/testpage/

Use display:flex on .idx-omnibar-form form and flex:1; .idx-omnibar-form form上使用display:flexflex:1; on its children elements as shown below: 在其子元素上,如下所示:

 .idx-omnibar-form{ display:flex; align-items:flex-end; } .idx-omnibar-form *{ flex:1; margin-right:5px; } 
 <div class="et_pb_code et_pb_module et_pb_code_0"> <form class="idx-omnibar-form idx-omnibar-extra-form"> <label for="omnibar" class="screen-reader-text" style="display:none">City, Zip Code, Address, or Listing ID</label> <input id="omnibar" class="idx-omnibar-input idx-omnibar-extra-input" type="text" placeholder="City, Zip Code, Address, or Listing ID"> <div class="idx-omnibar-extra idx-omnibar-price-container idx-omnibar-min-price-container"><label>Price Min</label><input class="idx-omnibar-min-price" type="number" min="0"></div> <div class="idx-omnibar-extra idx-omnibar-price-container idx-omnibar-max-price-container"><label>Price Max</label><input class="idx-omnibar-price" type="number" min="0"></div> <div class="idx-omnibar-extra idx-omnibar-bed-container"><label>Beds</label><input class="idx-omnibar-bed" type="number" min="0"></div> <div class="idx-omnibar-extra idx-omnibar-bath-container"><label>Baths</label><input class="idx-omnibar-bath" type="number" min="0" step="0.01" title="Only numbers and decimals are allowed"></div> <button class="idx-omnibar-extra-button" type="submit" value="Search"><i class="fa fa-search"></i><span>Search</span></button> </form> </div> 

I cannot preach enough about css flexbox. 我对CSS Flexbox不够了解。 Since it has become cross-browser compatible I have been using it on everything and I haven't written float in almost a year. 自从它变得可以跨浏览器兼容以来,我就在所有东西上都使用了它,并且我差不多一年都没有写过float

If this were my project I would add flex to the parent container (in your code the parent is <form> ) to get all of the children inline together. 如果这是我的项目,则将flex添加到父容器(在您的代码中,父容器为<form> ),以将所有子级内联在一起。 There are also other flex attributes you can use to adjust their positioning within the parent container. 您还可以使用其他flex属性来调整其在父容器中的位置。 In the example below I have chose justify-content:space-between to spread the children out so they go right to the corners. 在下面的示例中,我选择了justify-content:space-between将孩子散布开来,以便他们走到角落。 If you wanted them centered you could choose justify-content:center ! 如果您希望它们居中,则可以选择justify-content:center Flex also lets you adjust vertically. Flex还允许您垂直调整。 Here I have chosen align-items:stretch so that all of the child divs are the same height as the tallest sibling. 在这里,我选择了align-items:stretch以便所有子div的高度与最高的同级兄弟相同。

Then all you need to do is align the content inside of the child divs. 然后,您需要做的就是在子div中对齐内容。 You can flex those too if you want! 您也可以根据需要灵活调整!

Read more about flex here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 在此处阅读有关flex的更多信息: https : //css-tricks.com/snippets/css/a-guide-to-flexbox/

 .parent{ display:flex; justify-content:space-between; align-items:stretch; } .child{ flex: 0 0 20%; background-color:black; color:white; text-align:center; padding:2em; } 
 <div class="parent"> <div class="child"> 1 </div><!-- child --> <div class="child"> 2 </div><!-- child --> <div class="child"> 3 </div><!-- child --> </div><!-- parent --> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM