0

When the sentence is too big, there is a lot of white space left when collapsing it.

In the example below the word technician is too big for the div and is forced underneath, leaving a lot of space between appliance and the right border.

Is there a way to fix this with CSS or with jQuery?

problem

DIV Code:

width:28%;
float:left;
skobaljic
  • 9,379
  • 1
  • 25
  • 51
RomanK
  • 155
  • 1
  • 2
  • 13

1 Answers1

0

To break a word at any point line wraps then use word-break property of CSS with value break-all.

div {
  float: left;
  with: 28%;
  word-break: break-all;
}

Example:

div {
  background-color: #f00;
  float: left;
  width: 28%;
  word-break: break-all;
}
<div>
  Electrical Appliance Technician
</div>

If you want to hide the extra part with ... so do it like:

div {
  background-color: #f00;
  float: left;
  width: 28%;
  overflow-x: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
<div>
  Electrical Appliance Technician
</div>
MNR
  • 727
  • 1
  • 9
  • 23