Table overflows parent div when td content is too wide

纵然是瞬间 提交于 2019-12-05 17:30:33

问题


I prepared a JSFiddle to explain/show you my problem: http://jsfiddle.net/nz96C/

It looks alright at first, but when I add some text to #firsttd the whole table overflows the parent div once the tds whole width is used. I know how to solve this problem with CSS (#firstdiv {width:90px;overflow:hidden;}) but I don't know the exact number of pixels (percentage doesn't work). Also I don't want the text in the first td to wrap.

I hope you get my problem, I even have trouble explaining it in my first language.

EDIT: My goal is to have a table in which it doesn't matter how long the text in the first td is, the table should never overflow the parent div - without the text being wrapped. I want the text which overflows the first td just not to be shown.


回答1:


Same answer as another very recent topic:table-layout:fixed; + width. DEMO

table {
    table-layout:fixed;
    width:100%;
}
td {
    border: 1px solid black;
    overflow:hidden;/* optionnal*/
}
#firsttd {
    white-space: nowrap;
}


来源:https://stackoverflow.com/questions/24963291/table-overflows-parent-div-when-td-content-is-too-wide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!