简体   繁体   English

div中的自动换行文本

[英]word wrap text in div

I'm trying to get the product name for each item to fit into the div I've tried using word-wrap: break-word; 我正在尝试获取每个项目的产品名称以适合我尝试使用自动换行的div:break-word; // word-wrap: break-all; //自动换行:万能; but both didn't work. 但两者都不起作用。 I also tried setting the width of each div instead of % but didn't work text flows over the next items text. 我也尝试设置每个div的宽度而不是%,但是在下一个项目文本上没有文本流。

What am I doing wrong? 我究竟做错了什么?

 .scrolls { display: inline-block; overflow-x: scroll; overflow-y: hidden; border: solid transparent; width: 60vw; } .scrolls .product { display: inline-block; border: solid transparent; width: 30%; height: 240px; } .scrolls .product .details { width: 100%; height: 100%; font-size: 15px; display: inline-block; float: left; height: 100%; } .scrolls .product .details ul { width: 100%; height: 100%; list-style: none; padding: 0; margin: 0; } .scrolls .product .details .liProductName { max-width: 150px; word-break: break-all; border: 1px solid red; } 
 <div class="scrolls"> <div class="product" ng-repeat="i in products track by $index" align="center"> <div class="details"> <ul> <li class="liProductName"> Portable 20000mAh USB Power Bank LED LCD For Cell Phone External Battery</li> <li><img style="width: 90px; height: 120px;" data-ng-src="{{img}}" /></li> <li><button id="addItemBtn" class="btn btn-default" ng-click="addItem(i.productId)">Add</button></li> </ul> </div> </div> </div> 

try this below code with !important "word-wrap:break-word !important;" 在下面的代码中尝试使用!important“ word-wrap:break-word!important;”。

.scrolls .product .details .liProductName{
        max-width:150px;
        border:1px solid red;
        word-wrap:break-word !important;
    }

Well maybe you want to try something like this? 好吧,也许您想尝试这样的事情?

.scrolls .product .details .liProductName {
    max-width: 150px;
    border: 1px solid red;
    overflow-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

Otherwise maybe you want something like this: 否则,也许您想要这样的事情:

.scrolls .product .details .liProductName {
    max-width: 150px;
    word-break: break-word;
    border: 1px solid red;
}

This would do the job, also did do the changes in the codesnippet below. 这可以完成工作,也可以在下面的代码段中进行更改。

 .scrolls { display: inline-block; overflow-x: scroll; overflow-y: hidden; border: solid transparent; width: 60vw; } .scrolls .product { display: inline-block; border: solid transparent; width: 30%; height: 240px; } .scrolls .product .details { width: 100%; height: 100%; font-size: 15px; display: inline-block; float: left; height: 100%; } .scrolls .product .details ul { width: 100%; height: 100%; list-style: none; padding: 0; margin: 0; } .scrolls .product .details .liProductName1 { max-width: 150px; word-break: break-word; border: 1px solid red; } .scrolls .product .details .liProductName2 { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid red; } 
 <div class="scrolls"> <div class="product" ng-repeat="i in products track by $index" align="center"> <div class="details"> <ul> <li class="liProductName1"> Portable 20000mAh USB Power Bank LED LCD For Cell Phone External Battery</li> <li><img style="width: 90px; height: 120px;" data-ng-src="{{img}}" /></li> <li><button id="addItemBtn" class="btn btn-default" ng-click="addItem(i.productId)">Add</button></li> </ul> </div> </div> </div> <div class="scrolls"> <div class="product" ng-repeat="i in products track by $index" align="center"> <div class="details"> <ul> <li class="liProductName2"> Portable 20000mAh USB Power Bank LED LCD For Cell Phone External Battery</li> <li><img style="width: 90px; height: 120px;" data-ng-src="{{img}}" /></li> <li><button id="addItemBtn" class="btn btn-default" ng-click="addItem(i.productId)">Add</button></li> </ul> </div> </div> </div> 

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

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