-1

here is my fiddle, How do I wrap the content inside my DIV so it doesnt overlap my DIV? I know we can use

word-wrap: break-word;

but I have over 100 of these little "boxes" with numbers inside and I want everything to fit inside (about 4-5 digits long).

below is my css

thanks in advance

/* desk boxes*/
.desk_box_ver{ 
   width: 18px;
   height: 33px;
}   


.desk_box_hor{ 
  width: 23px;
  height: 10px;
}   


.desk_box_hor, .desk_box_ver { 
   position: absolute; 
   border: 4px solid black; 
   padding:10px;
}
alda1234
  • 204
  • 1
  • 4
  • 15

3 Answers3

0

Delete this

.desk_box_hor{ 
   width: 23px;
   height: 10px;
 } 

You are making the box larger than the numbers. They wont fit regardless, unless:

  • you make the font smaller;
  • white-space:wrap;
  • make the box size dynamic with padding

EDIT

To answer your response below

You can remove the inline styles via JQuery as follows:

$('.desk_box_hor').attr('style', function(i, style)
   {
   $(this).attr("style", "");
});

$('.desk_box_ver').attr('style', function(i, style)
   {
   $(this).attr("style", "");
});

Then apply css classes properly

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140
  • I cant really delete the sizing of them since I have a lot.. look at this [example](http://jsfiddle.net/wq07030y/).. I have over 200 of them – alda1234 Nov 24 '14 at 20:08
0

In order to scale the text based on the size of the container, see this post here: how to set font size based on container size?

The accepted answer has the best and most reliable solution.

To scale the container around the text, you can simply remove the width and height for the CSS involving the containers. Here is an updated version of your fiddle where I just deleted the width and height: http://jsfiddle.net/3qrxezjv/

Community
  • 1
  • 1
Dryden Long
  • 10,072
  • 2
  • 35
  • 47
0

Instead of imposing a fixed width, you could use min-width. This way the box won't be smaller than its content:

.desk_box_ver{ 
    min-width: 18px;
}   
.desk_box_hor{ 
    min-width: 23px;
}   

/* desk boxes*/
.desk_box_ver{ 
 min-width: 18px;
 height: 33px;
} 
.desk_box_ver:hover{
 cursor: pointer;
}
.desk_box_hor{ 
 min-width: 23px;
 height: 10px;
} 
.desk_box_hor:hover{
 cursor: pointer;
}
.desk_box_hor, .desk_box_ver { 
 position: absolute; 
 border: 4px solid black; 
 padding:10px;
}
<div class="desk_box_hor" id="desk_H15" data-rel="236" style="left:325px;top:50px;">18556</div>
<div class="desk_box_ver" id="desk_I06" data-rel="219" style="left:93px;top:100px;">25753</div>
Oriol
  • 274,082
  • 63
  • 437
  • 513
  • I updated my fiddle to show you an example of what I really have.. If it does expand the width . will it overlap the one next to it? – alda1234 Nov 24 '14 at 20:13
  • @alda1234 Yes, if the boxes are close, they may overlap when they grow. – Oriol Nov 24 '14 at 20:31