[英]Display table row width doesn't fix
I'm trying to make the div have same height so i used display table , problem that i having is the width will grow. 我正在尝试使div具有相同的高度,所以我使用了display table,问题是宽度会增大。 As an example try adding content in the tableright , when it is exceeded the width , it will not break to the next line but it will expand horizontally to the tableleft.
作为示例,请尝试在右上方添加内容,当其超出宽度时,它不会中断到下一行,但会水平扩展到左上方。
Please Advice. 请指教。 Below is the sample code
下面是示例代码
<div id="maintable">
<div id="table-row">
<div id="tableleft></div>
<div id="tableright></div>
</div>
</div>
<style>
#maintable
{display:table;
width:100%;
}
#table-row
{
display:table-row
width:100%;
}
#tableleft
{
width:60%;
display:table-cell;
}
#tableright
{
width:40%;
display:table-cell;
}
</style>
You made few syntax error there. 您在此处几乎没有语法错误。
Further to make sure if one big un spaced word is placed in table-cell i have used "table-layout: fixed;" 为了进一步确保是否在表格单元格中放置了一个大的未隔开的单词,我使用了“ table-layout:fixed;”。
check this fiddle: http://jsfiddle.net/5q9K8/17/ 检查这个小提琴: http : //jsfiddle.net/5q9K8/17/
The HTML: HTML:
<div id="maintable">
<div id="table-row">
<div id="tableleft">lorem</div>
<div id="tableright">ipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsumipsum</div>
</div>
</div>
The Css: CSS:
#maintable
{
display:table;
width:100%;
table-layout: fixed;
word-wrap:break-word;
}
#table-row
{
display:table-row;
width:100%;
}
#tableleft
{
width:60%;
display:table-cell;
background: #eef;
}
#tableright
{
width:40%;
display:table-cell;
background: #efe;
}
Add width as accordingly here just an example to show div height equal to table height. 相应地添加宽度,这里只是一个示例,以显示div高度等于表格高度。
css 的CSS
.maintable {
width:100%;
display: table;
border: 1px solid blue;
}
.maintable .table-row {
display: table-row;
border: 2px solid black;
}
.maintable .table-row .tableleft, .maintable .table-row .tableright {
display: table-cell;
border: 4px solid red;
}
.tableright {
width: 60%;
}
.tableleft {
width: 40%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.