Heim  >  Artikel  >  Web-Frontend  >  怎样才能让table中嵌套的并列td不撑破外面的table_html/css_WEB-ITnose

怎样才能让table中嵌套的并列td不撑破外面的table_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:14:201013Durchsuche

我定义了宽度设置为700像素的table,在里面有很多td.
  现在想如何确保里面嵌入的td不撑破外table?

而且,

...中的内容必须居中显示。用style='float:left'全部都居左显示了,不是我想要的效果。


表结构大致这样: 

<table width=700px border=1>    <tr align=center>        <td width=150px>内嵌内容A</td>        <td width=150px>内嵌内容b</td>        <td width=150px>内嵌内容c</td>        <td width=150px>内嵌内容d</td> <!--按理说,到这行就该换行显示了,可事实上没有-->       <td width=150px>内嵌内容e</td>    </tr></table>


 每个的宽度是150,按道理说,应该4个 后就自动换行的,可是事实上其并不自动换行,而是撑破了外table.

怎么才能解决这个问题呢。用DIV的不算,要重新设计整个CSS,时间上耗不起了。


回复讨论(解决方案)

换成 
ul

貌似没听说过TR里面的TD会换行显示吧??  

table中的td是不会换行的,因为你每个td的宽度都是一样的,所以当你的所有td宽度超过整个table的宽度时,系统会自动把table的宽度按td的比例平分给所有td

换成 
ul

楼主说了暂时不考虑CSS

楼主,你只能在TD里面嵌入新table

不能对TD循环,TD是不会自动换行的,只能对table循环

代码(必须用到float:left):

<table width=700px border=1>    <tr align=center>        <td width=150px><table style='float:left'><tr><td>内容1</td></tr></table></td>        <td width=150px><table style='float:left'><tr><td>内容2</td></tr></table></td>         <td width=150px><table style='float:left'><tr><td>内容3</td></tr></table></td>         <td width=150px><table style='float:left'><tr><td>内容4</td></tr></table></td>         <td width=150px><table style='float:left'><tr><td>内容5</td></tr></table></td>         <td width=150px><table style='float:left'><tr><td>内容6</td></tr></table></td>    </tr></table>

对不起,楼上我写错了,把TD写重复了,正确是这样:

<table width=700px border=1>    <tr align=center>        <td width=150px>          <table style='float:left'><tr><td>内容1</td></tr></table>          <table style='float:left'><tr><td>内容2</td></tr></table>          <table style='float:left'><tr><td>内容3</td></tr></table>          <table style='float:left'><tr><td>内容4</td></tr></table>          <table style='float:left'><tr><td>内容5</td></tr></table>       </td>    </tr></table>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn