简体   繁体   English

文字将不会包裹在我的flexbox容器中

[英]Text will not wrap inside my flexbox container

I'm having problems trying to get the text inside my flexbox container, instead it just spills out into the element to the right, how can I get both texts to wrap? 我在尝试将文本放入flexbox容器时遇到问题,取而代之的是将其溢出到右边的元素中,如何将两个文本都换行?

 <div style="width:100%; height:auto; display:flex; outline:1px solid red;"> <div style="width:30%; min-height:450px; outline:1px solid red; position:relative; display:flex;"> <div style="width:100%; height:auto; display:flex; flex-direction:column; padding:25px;"> <span style="font-size:20px; color:red; margin-bottom:20px; ">kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk</span> <p style="font-size:15px; color:red; line-height:28px; margin-bottom:20px;">cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</p> </div> </div> <div style="width:70%; min-height:450px; outline:1px solid red; display:flex; flex-direction:column; padding:25px; "> <table class="section_menu_pala_item_table" data-menu="entrantes" style="width:100%; border:none;"> <tr class="section_menu_pala_item_row" style="margin-bottom:4px;"> <th class="section_menu_pala_item_header" style="border:none; text-align:left;" width="15%">Plato</th> <th class="section_menu_pala_item_header" style="border:none;" width="1%">1/2</th> <th class="section_menu_pala_item_header" style="border:none;" width="1%">1</th> </tr> <!--append rows here--> </table> </div> </div> 

break-word on the div will result in this for ya div上的break-word将导致这种情况

 <div style="width:100%; height:auto; display:flex; outline:1px solid red;"> <div style="width:30%; min-height:450px; outline:1px solid red; position:relative; display:flex;"> <div style="width:100%; height:auto; display:flex; flex-direction:column; padding:25px; word-wrap: break-word;"> <span style="font-size:20px; color:red; margin-bottom:20px; ">kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk</span> <p style="font-size:15px; color:red; line-height:28px; margin-bottom:20px;">cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</p> </div> </div> <div style="width:70%; min-height:450px; outline:1px solid red; display:flex; flex-direction:column; padding:25px; "> <table class="section_menu_pala_item_table" data-menu="entrantes" style="width:100%; border:none;"> <tr class="section_menu_pala_item_row" style="margin-bottom:4px;"> <th class="section_menu_pala_item_header" style="border:none; text-align:left;" width="15%">Plato</th> <th class="section_menu_pala_item_header" style="border:none;" width="1%">1/2</th> <th class="section_menu_pala_item_header" style="border:none;" width="1%">1</th> </tr> <!--append rows here--> </table> </div> </div> 

I recommend to use word-wrap: break-word . 我建议使用word-wrap: break-word It will, in contrast to word-break , only create a break if an entire word cannot be placed on its own line without overflowing. 与分word-break相比,只有在无法将整个单词放在自己的行而不会溢出的情况下,才会产生分词。

As a side note, I strongly recommend start using external CSS style sheets and classes, as with inline you won't be able to reuse styles etc., and it is much more error prone and harder to maintain when mixed with all the markup. 附带说明一下,我强烈建议您开始使用外部CSS样式表和类,因为使用内联时,您将无法重复使用样式等,并且与所有标记混合使用时,它更容易出错且更难以维护。

Stack snippet 堆栈片段

 <div style="width:100%; height:auto; display:flex; outline:1px solid red;"> <div style="width:30%; min-height:450px; outline:1px solid red; position:relative; display:flex;"> <div style="width:100%; height:auto; display:flex; flex-direction:column; padding:25px;"> <span style="word-wrap: break-word;font-size:20px; color:red; margin-bottom:20px; ">kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk</span> <p style="word-wrap: break-word;font-size:15px; color:red; line-height:28px; margin-bottom:20px;">cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</p> </div> </div> <div style="width:70%; min-height:450px; outline:1px solid red; display:flex; flex-direction:column; padding:25px; "> <table class="section_menu_pala_item_table" data-menu="entrantes" style="width:100%; border:none;"> <tr class="section_menu_pala_item_row" style="margin-bottom:4px;"> <th class="section_menu_pala_item_header" style="border:none; text-align:left;" width="15%">Plato</th> <th class="section_menu_pala_item_header" style="border:none;" width="1%">1/2</th> <th class="section_menu_pala_item_header" style="border:none;" width="1%">1</th> </tr> <!--append rows here--> </table> </div> </div> 

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

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