dongwuxie7976 2014-04-13 20:19
浏览 25
已采纳

Php列表宽度

I'm trying to have my columns the same width, when I have empty columns they are the correct size but when I insert tables from a MySQL database, they change and one column is bigger than the others, the one named 'BristolQualification'. I think it might be something to do with the actual table because I've tried moving BristolQualification around and it's the same size in each different column. There are two BathQualification because I was just playing around and testing. Does anyone know why this could be happening? I've tried replacing them with width="25%" (because there are 4 columns 25*4 = 100%).

<?php 
mysql_connect("host", "user", "pwd") or die(mysql_error()); 
mysql_select_db("db") or die(mysql_error());

$data = mysql_query("
SELECT  
`Bath`.`BathCountry` ,  
`Bristol`.`BristolCountry` ,  
`Bath`.`BathQualification` ,  
`Bristol`.`BristolQualification` 
FROM  
`Bristol` 
LEFT JOIN  
`Bath` 
ON  
`Bristol`.`BristolCountry` =  `Bath`.`BathCountry` 
ORDER BY  
`Bristol`.`BristolCountry`;
") 
or die(mysql_error());

Echo "<table class=\"imagetable\" border cellpadding=3 style=\"width:100%;\">"; 
while($info = mysql_fetch_array( $data )) 
{ 
Echo "<tr>"; 
Echo "<th width=\"100\">Country:</th>
   <th class=\"Bristol\" width=\"100\">Qualifications to Bristol:</th>
   <th class=\"USW\" width=\"100\">Qualifications to USW:</th> 
   <th class=\"Bath\" width=\"100\">Qualifications to Bath:</th>"; 
Echo "</tr>";
Echo "<tr>";
Echo "<td width=\"100\">".$info['BristolCountry'] . "</td> 
   <td class=\"Bristol2\" width=\"100\">".$info['BathQualification'] . " </td> 
   <td class=\"Bath2\" width=\"100\">".$info['BathQualification'] . " </td> 
   <td class=\"USW2\" width=\"100\">".$info['BristolQualification'] . " </td> "  ;
Echo "</tr>"; 
 } 
 Echo "</table>"; 
 ?>
  • 写回答

3条回答 默认 最新

  • douxingmou4533 2014-04-13 20:23
    关注

    You should use this CSS properties : word-break:break-all; word-wrap:break-word(force your content to fit the block's width) and table-layout:fixed to your table.

    table {
        word-break:break-all;
        word-wrap:break-word;
        table-layout:fixed;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看