Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 固定宽度中间div和两侧的两个弹性宽度div_Css_Html_Layout_Elasticlayout - Fatal编程技术网

Css 固定宽度中间div和两侧的两个弹性宽度div

Css 固定宽度中间div和两侧的两个弹性宽度div,css,html,layout,elasticlayout,Css,Html,Layout,Elasticlayout,我正在尝试创建一个布局,其中一个div中有三个div,占据了页面的100%宽度。中间分区将具有固定的宽度,两个外部分区将分别占据剩余空间的50%。使用CSS可以实现这一点吗 我用以下代码设置了一个小提琴,但它不起作用,我试图实现这一点: <div id="outerbox"> <div id="leftbox">(elastic width) This should occupy all the space in the grey box to the left

我正在尝试创建一个布局,其中一个div中有三个div,占据了页面的100%宽度。中间分区将具有固定的宽度,两个外部分区将分别占据剩余空间的50%。使用CSS可以实现这一点吗

我用以下代码设置了一个小提琴,但它不起作用,我试图实现这一点:

<div id="outerbox">
    <div id="leftbox">(elastic width) This should occupy all the space in the grey box to the left of the red box</div>
    <div id="centerbox">(fixed-size) should be in the center of the grey box</div>
    <div id="rightbox">(elastic width) This should occupy all the space in the grey box to the right of the red box</div>
</div>
James

添加
宽度:计算(50%-150px)
#左框
#右框
(150px=中心框宽度的一半)

浏览器支持:

添加
宽度:计算(50%-150px)
#左框
#右框
(150px=中心框宽度的一半)

浏览器支持:

添加
宽度:计算(50%-150px)
#左框
#右框
(150px=中心框宽度的一半)

浏览器支持:

添加
宽度:计算(50%-150px)
#左框
#右框
(150px=中心框宽度的一半)


浏览器支持:

不确定仅使用CSS是否可以实现这一点,但这里有一段方便的JavaScript代码,可以帮助您更有效地管理固定和基于百分比的页面宽度:

function resize() {
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

}
然后,您可以在页面加载和页面调整时调用
resize()
函数。比如:

从这里开始,由于您有一个计算出的页面宽度,因此可以相应地调整单个
div
s的大小:

document.getElementById("leftbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("rightbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("centerbox").style.width = 300 + "px";

centerbox
保持300像素的固定宽度,而
leftbox
rightbox
的宽度等于屏幕宽度减去300像素除以2。

不确定仅使用CSS是否可以实现这一点,但这里有一段方便的JavaScript代码,可以帮助您更有效地管理固定和基于百分比的页面宽度:

function resize() {
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

}
然后,您可以在页面加载和页面调整时调用
resize()
函数。比如:

从这里开始,由于您有一个计算出的页面宽度,因此可以相应地调整单个
div
s的大小:

document.getElementById("leftbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("rightbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("centerbox").style.width = 300 + "px";

centerbox
保持300像素的固定宽度,而
leftbox
rightbox
的宽度等于屏幕宽度减去300像素除以2。

不确定仅使用CSS是否可以实现这一点,但这里有一段方便的JavaScript代码,可以帮助您更有效地管理固定和基于百分比的页面宽度:

function resize() {
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

}
然后,您可以在页面加载和页面调整时调用
resize()
函数。比如:

从这里开始,由于您有一个计算出的页面宽度,因此可以相应地调整单个
div
s的大小:

document.getElementById("leftbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("rightbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("centerbox").style.width = 300 + "px";

centerbox
保持300像素的固定宽度,而
leftbox
rightbox
的宽度等于屏幕宽度减去300像素除以2。

不确定仅使用CSS是否可以实现这一点,但这里有一段方便的JavaScript代码,可以帮助您更有效地管理固定和基于百分比的页面宽度:

function resize() {
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
}

// older versions of IE

else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

}
然后,您可以在页面加载和页面调整时调用
resize()
函数。比如:

从这里开始,由于您有一个计算出的页面宽度,因此可以相应地调整单个
div
s的大小:

document.getElementById("leftbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("rightbox").style.width = (viewportwidth - 300)/2 + "px";
document.getElementById("centerbox").style.width = 300 + "px";

centerbox
保持300像素的固定宽度,而
leftbox
rightbox
的宽度等于屏幕宽度减去300像素,除以2。

只需使用固定宽度的浮点值即可

#fixed{float:left;width:360px;background-color:green;height:100%;color:yellow;}

#elastic{background-color:#ddd;height:100%;color:grey;}

只需使用固定宽度的浮动即可

#fixed{float:left;width:360px;background-color:green;height:100%;color:yellow;}

#elastic{background-color:#ddd;height:100%;color:grey;}

只需使用固定宽度的浮动即可

#fixed{float:left;width:360px;background-color:green;height:100%;color:yellow;}

#elastic{background-color:#ddd;height:100%;color:grey;}

只需使用固定宽度的浮动即可

#fixed{float:left;width:360px;background-color:green;height:100%;color:yellow;}

#elastic{background-color:#ddd;height:100%;color:grey;}

哪些浏览器支持此功能?上帝,这是一个如此美妙的建筑,谢谢!!哪些浏览器支持这一点?上帝,这是一个如此美妙的建筑,谢谢!!哪些浏览器支持这一点?上帝,这是一个如此美妙的建筑,谢谢!!哪些浏览器支持这一点?上帝,这是一个如此美妙的建筑,谢谢!!