-1

How can I truncate text from N words by using CSS?

HTML:

<h5 style="font-size:14px"><span class="icon-home"></span>  B/1 Rajasthan Appartment, Kabirchowk, Sabarmati, Ahmedabad</h5>

I want to trunacate text after a kabirchowk how can I do this?

Shah Rushabh
  • 147
  • 4
  • 16
  • You can't really truncate a text after a specific word/char, but you can set the width of the `h5` element and have the `overflow: hidden` to make sure that everything that doesn't fit inside that width will not be displayed. – Dekel Oct 04 '16 at 17:05
  • @Dekel still it not working – Shah Rushabh Oct 04 '16 at 17:09
  • B/1 Rajasthan Appartment, Kabirchowk, Sabarmati, Ahmedabad I applied following code. – Shah Rushabh Oct 04 '16 at 17:11
  • but if you have `width: 100%` it will take all width. you can set it to `width: 100px` (or some other value). – Dekel Oct 04 '16 at 17:14
  • Does this answer your question? [How to truncate text in HTML](https://stackoverflow.com/questions/16150120/how-to-truncate-text-in-html) – Lucas S. May 20 '20 at 05:49

1 Answers1

0

I found it. it worked for me.

 <h5 style="font-size:14px;width: 100%;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;"><span class="icon-home"></span>  <?php echo $p["Address1"];?></h5>
Shah Rushabh
  • 147
  • 4
  • 16