admin管理员组文章数量:1322534
in my angularjs/ionic mobile application I have implemented a list of messages. Now I want to modify it, so that if the message text is wider than the div container it should cut the string and adds 3 dots.
My message list looks like this:
<ion-list ng-repeat="message in messages">
<ion-item can-swipe="true" class="item-icon-left item-icon-right">
<i class="icon ion-email-unread"></i>
<div class="row">
<span class="col col-50">
<h2>{{message.title}}</h2>
</span>
<span class="col col-50 content-right text-small">
{{message.dateString}}
</span>
</div>
<div class="row">
<span class="col text-small">
{{message.text}}
</span>
</div>
<i class="icon ion-chevron-right"></i>
<ion-option-button class="button-dark">
More
</ion-option-button>
<ion-option-button class="button-assertive">
Delete
</ion-option-button>
</ion-item>
</ion-list>
How can I do this dynamically, so that it really depends on the width of the device/container?
in my angularjs/ionic mobile application I have implemented a list of messages. Now I want to modify it, so that if the message text is wider than the div container it should cut the string and adds 3 dots.
My message list looks like this:
<ion-list ng-repeat="message in messages">
<ion-item can-swipe="true" class="item-icon-left item-icon-right">
<i class="icon ion-email-unread"></i>
<div class="row">
<span class="col col-50">
<h2>{{message.title}}</h2>
</span>
<span class="col col-50 content-right text-small">
{{message.dateString}}
</span>
</div>
<div class="row">
<span class="col text-small">
{{message.text}}
</span>
</div>
<i class="icon ion-chevron-right"></i>
<ion-option-button class="button-dark">
More
</ion-option-button>
<ion-option-button class="button-assertive">
Delete
</ion-option-button>
</ion-item>
</ion-list>
How can I do this dynamically, so that it really depends on the width of the device/container?
Share Improve this question asked Jul 14, 2015 at 11:26 KingalioneKingalione 4,2756 gold badges51 silver badges89 bronze badges 1- You can add :after content with ... and overflow hidden – sertsedat Commented Jul 14, 2015 at 11:29
2 Answers
Reset to default 10You don't do that with JS.
Simply use CSS's overflow
and text-overflow
properties:
div {
width: 50px;
overflow: hidden;
text-overflow: ellipsis;
}
<div>1234567890123456789012345678901234567890</div>
You can achieve this easily by using CSS and specifying a width
for your content and adding a text-overflow
style with the value of elipsis
.
#crop-text {
/* essential */
text-overflow: ellipsis;
width: 160px;
white-space: nowrap;
overflow: hidden;
/* for good looks */
padding: 10px;
border: 1px #000 solid;
}
<div id="crop-text">Hello, this is a really long text string.</div>
This tutorial explains what you need to do. http://davidwalsh.name/css-ellipsis
本文标签: htmljavascriptangularjs cut string to fit in a divStack Overflow
版权声明:本文标题:html - javascriptangularjs cut string to fit in a div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109543a2421180.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论