简体   繁体   English

如何在flexitem中顶部对齐TEXTAREA和TEXT-input控件?

[英]How to top-align TEXTAREA and TEXT-input controls in flexitem?

First I used the flex: property to make two adjacent flexitems grow and shrink when the browser window was resized. 首先,我使用flex:属性来使两个相邻的flexitem在调整浏览器窗口大小时增长和收缩。 That worked. 那行得通。

Then I put a TEXTAEA element into the second dynamic flexitem. 然后,我将TEXTAEA元素放入第二个动态flexitem中。 That worked fine. 很好。

Added a single-line TEXT input element next to the textarea and observed that the bottom line of the text input element aligned with the bottom line of the textarea, but I want the top lines of the two elements to align. 在textarea旁边添加了一行TEXT输入元素,并观察到text输入元素的底线与textarea的底线对齐,但是我希望两个元素的顶线对齐。 How can I do that without scripting using CSS only? 不使用CSS编写脚本怎么办?

 .parent { display: flex; background-color: yellow; } .verttop { align-items: flex-start; } .dimen { height: 50px; width: 50px; } .placeholder { background-color: khaki; width: 300px; } .bs1 { background-color: green; width: 20px; } .bs2 { flex: 1 1 auto; background-color: cyan; } .bs3 { flex: 1 1 auto; background-color: red; } .bs4 { background-color: gray; width: 100px; } 
 <div class="parent"> <div class="placeholder dimen"></div> <div class="bs1 dimen"></div> <div class="bs2 dimen"></div> <div class="bs3"> <textarea rows="10" cols="18">This is a fairly lengthy and annoyingly meaningless sentence. </textarea> <input class="verttop" type="text" value="Hello"> </div> <div class="bs4 dimen"></div> </div> 

You can do this by making .bs3 flex and aligning its items. 您可以通过弯曲.bs3并对齐其项目来实现。

.bs3 {
  flex: 1 1 auto;
  background-color: red;
  display: flex;
  align-items: flex-start;
}

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

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