
| A | B | C |
所以A和B列的宽度应与其内容的宽度相匹配,但C的宽度应该继续,直到表结束。
好的,我可以指定A和B的宽度(以像素为单位),但是问题是这些列的内容的宽度不是固定的,所以如果我设置了一个固定的宽度,它将不完全匹配内容:(
PS:我没有使用实际的表项,而是包含在div中的DL列表。 div有显示:table,dl有显示:table-row和dt / dd显示:table-cell …
解决方法 如果我理解你,你有表格数据,但是你想在浏览器中使用div元素(AFAIK表和带有display:table的表格大致相同)表示。(这里是一个工作的Jsfiddle:http://jsfiddle.net/roimergarcia/CWKRA/)
标记:
<div class='thetable'> <div class='theRow'> <div class='theCell' >first</div> <div class='theCell' >test</div> <div class='theCell bigCell'>this is long</div> </div> <div class='theRow'> <div class='theCell'>2nd</div> <div class='theCell'>more test</div> <div class='theCell'>it is still long</div> </div></div>
和CSS:
.thetable{ display:table; wIDth:95%; /* or whatever wIDth for your table*/}.theRow{display:table-row}.theCell{ display:table-cell; padding: 0px 2px; /* just some padding,if needed*/ white-space: pre; /* this will avoID line breaks*/}.bigCell{ wIDth:100%; /* this will shrink other cells */} 可悲的是,一年前我无法做到这一点,当时真的需要它-_-!
总结以上是内存溢出为你收集整理的html – 如何使表格单元格收缩宽度仅适合其内容?全部内容,希望文章能够帮你解决html – 如何使表格单元格收缩宽度仅适合其内容?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)