colspan width issue
【问】
I'm having trouble setting fixed widths on columns which use colspan.
It seems that neither IE8, Firefox or Chrome can figure out how to correctly size columns with colspan.
Try the following code to see the problem in action:
<h2>One table with colspans, incorrect cell dimensions</h2>
<table border="1">
<tr>
<td style="width:20px;">20</td>
<td style="width:50px;" colspan="2">50</td>
<td>a</td>
<td>a</td></tr>
<tr>
<td style="width:50px;" colspan="2">50</td>
<td style="width:20px;">20</td>
<td>a</td>
<td>a</td></tr>
</table>
<h2>Split tables, correct cell dimensions</h2>
<table border="1">
<tr>
<td style="width:20px;">20</td>
<td style="width:50px;">50</td>
<td>a</td>
<td>a</td></tr>
</table>
<table border="1">
<tr>
<td style="width:50px;">50</td>
<td style="width:20px;">20</td>
<td>a</td>
<td>a</td></tr>
</table>
Can anyone explain why this might be happening, and if there is a workaround.
EDIT:
have tried doctypes
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
【答】
Because your column widths are contradicting. In row 1 you have columns widths 20, 50/2; in row 2 you have column widths 50/2, 20.
Row 1, Column 1 is defined as 20.
Row 1, Column 2 is defined as 50.
Row 2, Column 1 is defined as 50.
Row 2, Column 2 is defined as 20.
You can't have overlapping colspans of different widths, the table cells need to line up. You're trying to draw this table:
|-----|----------|
|----------|-----|
Which is not valid since the columns don't line up. In order to do this you need to add more columns:
|-----|----.-----|
|-----.----|-----|
Where "." is a column that is hidden by the column span. Try this HTML:
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
</head>
<body>
<table border="1" style="table-layout: fixed;">
<col style="width: 20px;"/>
<col style="width: 30px;"/>
<col style="width: 20px;"/>
<tbody>
<tr>
<td>20</td>
<td colspan="2">50</td>
</tr>
<tr>
<td colspan="2">50</td>
<td>20</td>
</tr>
</tbody>
</table>
</body>
</html>
From: https://stackoverflow.com/questions/5373893/colspan-width-issue
colspan width issue的更多相关文章
- true_kb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 拆分SharePoint 2013 中CreatedModifiedInfo 的时间
最近在自定义DisForm.aspx页面时 发现 创建时间信息无法进行拆分,人事MM只想要修改时间,去掉创建人,创建时间和修改人. 于是我的重新研究下在SPD里面如何去拆分这个时间. 在详情页面上找到 ...
- JQuery中对各种域进行隐藏和显示操作
操作的基本步骤: (1)导入jquery相关jar <script type="text/javascript" src="jquery-1.1.3.pack.js ...
- JDBC之数据连接
:数据库语句: create database LandDB; use LandDB; create table T_BL_CANTON_CODE ( CTN_CODE int primary key ...
- ASP.NET+ashx+jQuery动态添加删除表格
aspx: <script src="../script/jquery-1.4.4.min.js" type="text/javascript" lang ...
- dwz+jquery+fileupload+springmvc实现文件上传 及图片预览
1 前台jsp:文件的上传利用了iframe实现局部刷新功能.使用了apache的fileupload组件,用到的jar: commons-fileupload.jar,commons-io.jarD ...
- js barcode 打印
新建 html <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset=&quo ...
- asp.net get图
前段 <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat=& ...
- HTML 使用表格制作简单的个人简历
复习一下HTML,用表格做一个简单的个人简历 <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...
随机推荐
- STM32的PWM输入模式设置并用DMA接收数据
参考 :STM32输入捕获模式设置并用DMA接收数据 PWM input mode This mode is a particular case of input capture mode. The ...
- C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\文件不断增长,如何处理?
很久没有写博了.最近半年除了忙活布置新家和过年期间走亲访友之外,都是在公司处理一些项目中的杂事:连家里买的很多书都停下来没看了,感觉这段时间在事业和学习上一直都是忙忙碌碌,却又碌碌无为. 吐槽完,说正 ...
- [Go] 子类 调用 父类 的 属性、方法
package main import ( "fmt" ) type A struct { Text string Name string } func (a *A) Say() ...
- C++11 bind
#include <iostream> #include <functional> using namespace std; int func(int a, int b) { ...
- Revit API切换三维视图
切换视图必须在事务结束之后,这个困惑了半天,记录一下. , , -));//斜视45度 ts.Commit(); //切换视图必须在事务结束后,否则会提 ...
- window.onbeforeunload() 事件调用ajax
经常有这样的需求,就是在离开某个web页面时,用户不一定点注销,这样会导致会话不能及时销毁.为实现用户离开页面时,自动注销功能,需要在web页面的onbeforeunload事件处理函数中发送注销命令 ...
- iPhone系统常用文件夹位置
1. [/Applications] 常用软件的安装目录 2. [/private /var/ mobile/Media /iphone video Recorder] iphone v ...
- 关于面试总结6-SQL经典面试题
前言 用一条SQL 语句查询xuesheng表每门课都大于80 分的学生姓名,这个是面试考sql的一个非常经典的面试题 having和not in 查询 xuesheng表每门课都大于80 分的学生姓 ...
- jquery插件--在input下输入密码时提示大写锁定键
//密码大写输入提示 function capitalTip(id){ $('#' + id).after('<div class="capslock" id="c ...
- 摩登家庭第一季/全集Modern Family迅雷下载
本季Modern Family Season 1 第一季(2009)看点:<摩登家庭>瞄准的是三对各有不同的美国家庭:一对普通父母与三个孩子.一对同性恋夫夫从越南领养了养女组成三口之家,一 ...