2013-03-23 35 views
0

我最近遇到一個奇怪的問題用表格單元格內溢出自動DIV中(是的,我必須保持表)。文本溢出不換:汽車;寬度:100%的div當它是一個表

的DIV中的文本時,它是在表內不會換行。如果我把div放在另一個div中,它就可以完美運行。

我的臨時解決方案是使用JavaScript來迫使寬度但這是窮人和不與大小調整得非常好對付。

如果有人有任何想法,我會很高興聽到。

在這裏看到的代碼:

http://jsfiddle.net/jNZNF/

<table style="width: 400px;" border="1"> 
<tr><td> 
<div style="width: 100%; overflow: auto; height: 200px; border: 1px solid blue;"> 
ip\84.23.214.125:27960\name\Ze_Pequeno\password\bs\racered\1\raceblue\0\rate\25000\ut_timenudge\30\cg_rgb\153,0,0\funred\tridente\funblue\katana\cg_predictitems\0\cg_physics\1\gear\FHAOWRA\snaps\20\model\sarge\headmodel\sarge\team_model\james\team_headmodel\*james\color1\4\color2\5\handicap\100\sex\male\cl_anonymous\0\teamtask\0\cl_guid\49B4985AFD5E18C17EAC67AF5A6F4247\weapmodes\00000111220000020000 
</div> 
</td></tr></table> 


<div style="width: 400px; border:1px solid pink"> 
<div style="width: 100%; overflow: auto; height: 200px; border: 1px solid blue"> 
ip\84.23.214.125:27960\name\Ze_Pequeno\password\bs\racered\1\raceblue\0\rate\25000\ut_timenudge\30\cg_rgb\153,0,0\funred\tridente\funblue\katana\cg_predictitems\0\cg_physics\1\gear\FHAOWRA\snaps\20\model\sarge\headmodel\sarge\team_model\james\team_headmodel\*james\color1\4\color2\5\handicap\100\sex\mal e\cl_anonymous\0\teamtask\0\cl_guid\49B4985AFD5E18C17EAC67AF5A6F4247\weapmodes\00000111220000020000 
</div> 
</div> 

回答

1

除非我誤解你了,這應該這樣做:

<table style="width: 400px;" border="1"> 
<tr><td> 
<div style="width: 100%; overflow: auto; height: 200px; border: 1px solid blue;"> 
ip\84.23.214.125:27960\name\Ze_Pequeno\password\bs\racered\1\raceblue\0\rate\25000\ut_timenudge\30\cg_rgb\153,0,0\funred\tridente\funblue\katana\cg_predictitems\0\cg_physics\1\gear\FHAOWRA\snaps\20\model\sarge\headmodel\sarge\team_model\james\team_headmodel\*james\color1\4\color2\5\handicap\100\sex\male\cl_anonymous\0\teamtask\0\cl_guid\49B4985AFD5E18C17EAC67AF5A6F4247\weapmodes\00000111220000020000 
</div> 
</td></tr></table> 

小提琴:http://jsfiddle.net/ayAh7/1/

<div style="width: 400px; border:1px solid pink"> 
<div style="width: 100%; overflow: auto; height: 200px; border: 1px solid blue"> 
ip\84.23.214.125:27960\name\Ze_Pequeno\password\bs\racered\1\raceblue\0\rate\25000\ut_timenudge\30\cg_rgb\153,0,0\funred\tridente\funblue\katana\cg_predictitems\0\cg_physics\1\gear\FHAOWRA\snaps\20\model\sarge\headmodel\sarge\team_model\james\team_headmodel\*james\color1\4\color2\5\handicap\100\sex\mal e\cl_anonymous\0\teamtask\0\cl_guid\49B4985AFD5E18C17EAC67AF5A6F4247\weapmodes\00000111220000020000 
</div> 
</div> 
+0

這是正確的答案,但是,對於我的情況它不工作,因爲我無法調整表屬性(沒有在問題中說明)。會接受這個答案。謝謝。 – 2013-03-23 16:17:08

3

添加word-break:break-all規則,你的表(或DIV表內)。既然你基本上有一個長字符串(沒有空格),除非你強制它,否則瀏覽器不會打破它。

jsFiddle example

+0

這是結束了,我的工作 - 但是 - 我覺得正確的答案是「桌面佈局:固定的」一個是因爲這不會包裝文本,但會迫使它在div內溢出並且不會溢出表格。 – 2013-03-23 16:16:46