[英]unstyled list drops text in next row. how to stop this?
I'm about to build a simple menu card with bootstrap.我打算用引导程序构建一个简单的菜单卡。 I'm not a dev pro so I've decided to list them with unstyled list.我不是开发专家,所以我决定用无样式列表列出它们。 I also defined span with float: right that the price is always right aligned.我还用 float: right 定义了跨度,即价格总是右对齐。 Problem now is that when I resize my browser to view output for different devices, the price drops into the next row when the column is too tight.现在的问题是,当我调整浏览器大小时以针对不同设备查看 output 时,当列太紧时价格会下降到下一行。 How to avoid this?如何避免这种情况?
<ul class="list-unstyled">
<li>rashcook omlette +khobz*<span><u>8.5€</u></span></li>
<li style="padding-left: 10px;">+rinderschinken<span><u>3.5€</u></span></li>
<li style="padding-left: 10px;">+avocado-minze<span><u>3€</u></span></li>
<li style="padding-left: 10px;">+tomaten-salsa<span><u>2.5€</u></span></li>
</ul>
You can define behavior for different screen sizes with bootstrap using sm
, md
, lg
, xl
and xxl
.您可以使用sm
、 md
、 lg
、 xl
和xxl
定义不同屏幕尺寸的行为。
To cause a newline in this case, you can force the <u>
element to display as block
instead of inline
on screens smaller than sm
(576px by default).要在这种情况下产生换行符,您可以强制<u>
元素在小于sm
(默认为 576 像素)的屏幕上显示为block
而不是inline
。
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/> <div style="width: 300px"> <ul class="list-unstyled"> <li>rashcook omlette +khobz*<u class="d-block d-sm-inline float-sm-end">8.5€</u></li> <li class="ps-2">+rinderschinken<u class="d-block d-sm-inline float-sm-end">3.5€</u></li> <li class="ps-2">+avocado-minze<u class="d-block d-sm-inline float-sm-end">3€</u></li> <li class="ps-2">+tomaten-salsa<u class="d-block d-sm-inline float-sm-end">2.5€</u></li> </ul> </div>
I replaced the padding by 0.5rem
(8px) with the class ps-2
.我用 class ps-2
替换了0.5rem
(8px) 的填充。
<ul class="list-unstyled"> <li style="padding-left: 10px;">rashcook omlette +khobz*<span><u>8.5€</u></span></li> <li style="padding-left: 10px;">+rinderschinken<span><u>3.5€</u></span></li> <li style="padding-left: 10px;">+avocado-minze<span><u>3€</u></span></li> <li style="padding-left: 10px;">+tomaten-salsa<span><u>2.5€</u></span></li> </ul>
can you try like this?你能这样试试吗? If not, I suggest you look at bootstrap grid.如果没有,我建议你看看 bootstrap grid。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.