Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

html - Why TD width is not working or not followed?

Original question: Does HTML <table> have a default width?

Recently someone asked a question somewhere along these lines, and got me wondering.

Take this for example.

http://jsfiddle.net/rqmNY/1/

In this fiddle, if you were to check its width (I'm using inspect element from chrome), it shows 100px, working as intended.

Lets add a few more "td"s in, and we shall see that the "td:100px" css is being ignored.

http://jsfiddle.net/rqmNY/2/

As you can see, now it's 83px instead of 100px as originally intended.

But let's say, I move back to fewer TD's (7), and I add in a wider width to each TD element (500px), the result is that the width of the td gets stuck at 119px.

http://jsfiddle.net/rqmNY/6/

And finally, let's say I have a table of 2000px width, and td of 100px width, and many td elements. http://jsfiddle.net/rqmNY/7/

Now the table width overrides the TD width, and expands the td's width to 222px.

Can anyone explain this behavior?

p.s. Note that in all cases, inspect element tool tells me that the width is always corresponding to the css, it's just the final result not showing correctly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have you tried adding display:inline-block to your TD CSS? That forces the browser to not ignore your TD width.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...