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
411 views
in Technique[技术] by (71.8m points)

css - Understanding display:table-cell; functioning

Please note that I am not trying to resolve any specific issue, but trying to understand what's causing this issue.

I have set the width, height and display of some divs, but the height/width settings are not being honored. The text is also being pushed downward.

http://jsfiddle.net/k7esv/

1) Why does it push the text downward when height is set in table-row then BUT when height is removed, it places text at the top?

2) Why are the width/height settings not honored?

3) Why doesn't setting the margin property have any effect on them either?

http://jsfiddle.net/k7esv/1/

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

1) This seems to be a rendering issue specific to Firefox. Setting the vertical-align property on the divs fixes it. top, middle, or bottom all seem to work. I don't understand myself what FF is doing when there is a height but no vertical-align set; it might be a bug.

2) The width and height are honored, but they are subject to table sizing rules. When a table does not have enough room to give each of the cells the width they have specified, it will give more room to cells that have more content. This is what was happening with your example. If you look at my example below, you will see that when the parent element is wider than the sum total of the table cells' widths, the cells respect the width. The height should always work (except in the case of the FF rendering issue I mentioned above).

3) Table cells don't have margins. Use border-spacing and display:table on a parent div.

http://jsfiddle.net/chad/k7esv/3/


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

...