简体   繁体   English

无法在DIV中进行垂直对齐

[英]Having trouble getting vertical alignment to work in a DIV

I'm having trouble getting items to vertically align in my DIV on Mac Chrome. 我无法在Mac Chrome的DIV中使项目垂直对齐。 Ideally I'd like to get this to work on browsers that run on Mac, but I'll start with Mac Chrome. 理想情况下,我想让它在Mac上运行的浏览器上运行,但我将从Mac Chrome开始。 My JSFiddle is here -- https://jsfiddle.net/f77ajz4d/ . 我的jsfiddle在这里- https://jsfiddle.net/f77ajz4d/ This is my HTML 这是我的HTML

<div id="search_form">

<form id="search-form" action="/users/lookup_races" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">

<input type="text" name="first_name" id="first_name" placeholder="First Name">
<input type="text" name="last_name" id="last_name" placeholder="Last Name">
<input type="text" name="item" id="item" placeholder="Item">
<input alt="Search" type="image" src="/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button">
</form>
</div>

and here's my style 这是我的风格

#search_form
{
background-color:red;
display:table-cell;
text-align: center;
vertical-align:middle;
} 

It is not an option to assign a fixed height to the DIV. 不能为DIV分配固定高度。 Given this, what am I missing in order to get my items to vertically align? 鉴于此,为了使我的物品垂直对齐,我缺少什么?

You can do something like: 您可以执行以下操作:

 #search_form { background: red; padding: 5px; } input { vertical-align: middle; } 
 <div id="search_form"> <form id="search-form" action="/users/lookup_races" accept-charset="UTF-8" method="get"> <input name="utf8" type="hidden" value="✓"> <input type="text" name="first_name" id="first_name" placeholder="First Name"> <input type="text" name="last_name" id="last_name" placeholder="Last Name"> <input type="text" name="item" id="item" placeholder="Item"> <input alt="Search" type="image" src="/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button"> </form> </div> 

This ensures that all input elements are vertically aligned to eachother, with an even padding around them. 这样可确保所有input元素彼此垂直对齐,并在其周围均匀填充。

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

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