Why are fixed table-layout td words not wrapping?
Asked Answered
V

3

5

I have a table that is being populated with different lengths of text. I have set the table-layout css property to fixed because it keeps pushing the table outside it's parent creating a horizontal scrollbar.

I want my td's to be exactly half of the table which will be full size of it's parent. I want my text to wrap inside the td's. Here is what it looks like:

I want the text to wrap around 20 so it doesn't overlap the other text. I can't use a <br />.

Here is a JSFiddle of the problem.

Viens answered 21/2, 2012 at 15:31 Comment(1)
The reason it happens in your case is that the browser doesn't know where to break the word. You don't have any spaces, so it breaks the box model.Gore
G
10

You could use word-wrap: break-word on the p. It worked in your jsFiddle, and it's compatible with IE as Microsoft developed it.

Gore answered 21/2, 2012 at 15:35 Comment(3)
Do you know why we have to add this css property? In normal situations when p tags aren't in this situation their words wrap as I would expect them to do here.Viens
You don't have any spaces in your text, therefore the browser considers it to be one long word. Browsers don't wrap long words unless that CSS declaration is made.Gore
Wow, Thanks I didn't even realize that haha.Viens
I
2

as you are setting container width smaller, try to increase container width, Check JSFiddle for demo, width 250 will break to the exact 20 position.

#container
{
    width: 250px;
}
p
{
 word-wrap: break-word
 }
Infect answered 21/2, 2012 at 15:36 Comment(1)
I need it to be this smaller width.Viens
F
2

The reason that it is not breaking is because there is no spaces in the string. As soon as you add a space to the set of numbers it breaks. Therefore, one way to fix that would be to assign word-wrap:break-work to the p selector.

Flapdoodle answered 21/2, 2012 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.