简体   繁体   English

多行文本的HTML + CSS Wrap和Align按钮文本位置

[英]HTML + CSS Wrap and Align button text position for multi-line text

I'm making a set of buttons to be used on mobile with a defined min-width and a max-width to make sure the buttons don't grow too wide in size for mobile screen sizes. 我正在制作一组要在移动设备上使用的按钮,并定义了最小宽度和最大宽度,以确保按钮的尺寸不会因移动屏幕尺寸而变得过大。

The texts within the buttons vary in size, and to accomodate for longer length text I made sure I white-wrap them to the next line. 按钮中的文本大小不同,为了适应较长的文本,我确保将它们白色包裹到下一行。 However, when I do so, the button position gets shifted down, while the text still align (see picture: Baby Toddlers under 6). 但是,当我这样做时,按钮位置会向下移动,而文本仍会对齐(请参见图片:6岁以下的婴儿)。

“ 6岁以下婴儿学步车”向下移动。

How do I make sure so that all buttons align in-line with each other and at the same time make sure the text wraps when needed? 如何确保所有按钮彼此对齐并同时确保需要时自动换行?

Thanks! 谢谢!

 #m-container { max-wdith:375px; width:375px; overflow:auto; height: 667px; max-height: 667px; border:1px solid black; } #m-search-ffv-carousel { padding:10px; overflow: auto; white-space: nowrap; float: left; margin-bottom: 0.5rem; } button.filter { background-color: #eee; border: 1px solid #ccc; color: #333; white-space: normal; cursor: pointer; overflow: hidden; text-align: center; margin-right: 0.65rem; min-width: 95px; max-width: 120px; min-height: 45px; text-transform: none; line-height: 16px; font-weight: 200; font-size: 0.775rem; display: inline-block; align-items: center; justify-content: center; top: 0px; 
 <h2>Mocked Mobile size</h2> <div id="m-container"> <div id="m-search-ffv-carousel"> <button class="filter" id="">Boys</button> <button class="filter" id="">Baby Toddlers under 6</button> <button class="filter" id="">Male</button> <button class="filter" id="">Female</button> <button class="filter" id="">Show more</button> </div> </div> 

Simply add vertical-align:top to button.filter. 只需将vertical-align:top添加到button.filter。

 #m-container { max-wdith:375px; width:375px; overflow:auto; height: 667px; max-height: 667px; border:1px solid black; } #m-search-ffv-carousel { padding:10px; overflow: auto; white-space: nowrap; float: left; margin-bottom: 0.5rem; } button.filter { vertical-align:top; background-color: #eee; border: 1px solid #ccc; color: #333; white-space: normal; cursor: pointer; overflow: hidden; text-align: center; margin-right: 0.65rem; min-width: 95px; max-width: 120px; min-height: 45px; text-transform: none; line-height: 16px; font-weight: 200; font-size: 0.775rem; display: inline-block; align-items: center; justify-content: center; top: 0px; 
 <h2>Mocked Mobile size</h2> <div id="m-container"> <div id="m-search-ffv-carousel"> <button class="filter" id="">Boys</button> <button class="filter" id="">Baby Toddlers under 6</button> <button class="filter" id="">Male</button> <button class="filter" id="">Female</button> <button class="filter" id="">Show more</button> </div> </div> 

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

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