简体   繁体   English

3网格布局:固定侧边栏和流体内容

[英]3 grid layout: fixed sidebars and fluid content

I want to create a layout whose its structure is a mixed-type. 我想创建一个布局,其结构是混合类型。 I want two sidebars: one in the left side, another in the right side - both of them has 250px of width; 我想要两个侧边栏:一个在左侧,另一个在右侧 - 两个都有250px的宽度; in the middle, I just want the content whose its width is fluid. 在中间,我只想要宽度适中的内容。

I can make some math to solve my problem like calc(100% - 500px) , but I really don't want to use CSS3 for this – I want a cross-browser solution, and it can be pure CSS2 or JavaScript. 我可以做一些数学来解决我的问题,比如calc(100% - 500px) ,但我真的不想使用CSS3 - 我想要一个跨浏览器的解决方案,它可以是纯CSS2或JavaScript。

Can someone suggest me something? 有人可以给我一些建议吗? It can be a grid system, functions, etc. 它可以是网格系统,功能等。

<div class="left"></div>
<div class="center"></div>
<div class="right"></div>

css CSS

.left{
    width: 250px;
    position: absolute;
    left: 0;
}
.center{
    display: table;
    position: absolute;
    left: 250px;
    right: 250px;
}
.right
    width: 250px;
    position: absolute;
    right: 0;
}
  1. Get the document width: 获取文档宽度:
    var documentWidth = $(document).width();
  2. Remove the 'px': 删除'px':
    documentWidth = documentWidth.split('px')[0];
  3. Calculate the width of the middle div: 计算中间div的宽度:
    var middleDivWidth = documentWidth - 500;
  4. Set the calculated width to the middle div: 将计算出的宽度设置为中间div:
    $('#middleDivId').css('width',middleDivWidth+'px');

CSS: CSS:

.div1 {
    width: 250px;
    float: left;
}
.div2 {
    overflow: hidden;
    width: auto;
    float:left;
}
.div3 {
    width: 250px;
    float: right;
}

JSFIDDLE 的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM