jquery - 基于 CSS 表格的布局行未扩展 100% 宽度

标签 jquery html css

我想将基于 CSS 表格的行的宽度扩展到浏览器宽度的 100%,而不破坏其余内容的布局。请注意,即使已将绿色标题栏设置为 100% 宽度,它也不会扩展到全宽。

我的代码可以在这里找到: http://codepen.io/anon/pen/HfnFv

CSS

html,body{
    overflow:visible;
    height:100%;padding:0;margin:0;
}
.header{background:green;position:absolute;}
.table{
    display:table;
    width:100%;
  position:relative;
    min-height:100%;
}
.trow{
    display:table-row;
    width:100%;
}
.left{
    width:30%;
    height:100%;
    background-color:#990000;
    color:#efefef;
    display:table-cell;
}
.left p{
    margin:100px 0;
}
.right{
    width:70%;
    height:100%;
    background-color:blue;
    color:#efefef;
    display:table-cell;
}

HTML

<div class="table">
<div class="trow header">
<p>
test
</p>
</div>
<div class="trow">
<div class="left">
<p>
test
</p>
</div>
<div class="right">
test
</div>
</div>
</div>

更新

已添加

position:absolute;

到标题行。

但我希望看到一个不绝对定位子元素的替代解决方案。

最佳答案

你的问题是因为我们无法用 css 模拟 colspan。由于一行位于包含两个单元格的另一行之上,因此该标题行应该是 colspan="2"。但由于这是不可能的,您的选择是:

  1. 改变你的结构。
  2. 如果你想保持你现在的结构,你唯一的选择是设置 您的 .header,使用 display:table-caption;caption-side:top; 作为以下示例:

CSS:

.trow.header{
    width:100%;
    display:table-caption;
    caption-side:top;
    background:green;
}

我用你自己的例子做了一个演示:

http://jsfiddle.net/3JQcb/

关于jquery - 基于 CSS 表格的布局行未扩展 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24153473/

相关文章:

javascript - 延迟解析后调用的函数范围

javascript - Google Chrome 中的 jQuery 问题?淡入淡出

javascript - 如何在没有滚动条的情况下对具有 "text-overflow: ellipsis"的文本实现水平滚动拖动功能?

html - 在页面中间将图像组合在一起

html - 在 CSS 中隐藏 HTML 标签

javascript - 将文本从跨度内传递到弹出窗口

javascript - dc.js 教程折线图渲染

javascript - 当设备音频正在播放时,视频不会播放,反之亦然

c# - 尽管将 ContentPlaceHolder 和 <div> 设置为宽度 :100%,但内容超出了屏幕

jquery - 将 AJAX 转换为 jQuery