gpt4 book ai didi

javascript - css div动态问题

转载 作者:行者123 更新时间:2023-11-28 11:02:42 25 4
gpt4 key购买 nike

我正在学习 CSS。我正在做一个小任务..

我有一个中心框,当它的宽度、高度发生变化时,它的所有页眉、页脚、左侧边栏、右侧边栏也应该相应地改变!

我做错了什么。请在下面找到我的代码:

<!doctype html>
<html lang="en">
<head>

<script src="jquery-1.10.1.min.js"></script>

<script>
var modified_width, modified_height;

function set_width_height(width,height){
var width_factor=width/1024;
var height_factor=height/768;
var scale_factor=(width_factor>height_factor)?width_factor: height_factor;
modified_width=width*scale_factor;
modified_height=height*scale_factor;
return {width:modified_width, height:modified_height};
}

$(document).ready(function(){
set_width_height(800,480)
/* var width2 = 1024 - modified_width;
var height2 = 768 - modified_height;*/
$("#id6").css({'width':modified_width, 'height':modified_height});
/*
$("#id6").css("width",modified_width);
$("#id6").css("height",modified_height);*/

// alert(modified_width)

width1 = (1024 - modified_width)/2;
height1 = (768 - modified_height)/2;
$("#id2").css("width",width1);
$("#id4").css("width",width1);
$("#id3").css("height",height1);
$("#id5").css("height",height1);
})
</script>
<style>
.inc {
position:absolute;
border:1px solid white;
}

#id1{
width:1024px;
height:768px;
}

#id2{
left:0;
top:0;
bottom:0;
width:20%;
height:100%;
background:red;
}
#id3{
top:0;
left:20%;
width:60%;
height:15%;
background:pink;
}
#id4{
right:0;
top:0;
bottom:0;
width:20%;
background:green;
}
#id5{
bottom:0;
left:20%;
height:15%;
width:60%;
background:yellow;
}
#id6{
top:25%;
left:25%;
width:60%;
height:70%;
background:black;
}
</style>
</head>
<body>
<div id="id1" class="mainc">
<div id="id2" class="inc" >
B
</div>

<div id="id3" class="inc" >
D
</div>
<div id="id4" class="inc">
C
</div>
<div id="id5" class="inc">
E
</div>
<div id="id6" class="inc">
F
</div>
</div>
</body>
</html>

编辑: Fiddle

最佳答案

我不明白为什么您需要所有这些 javascript 来获得您想要的布局。如果你真的想学习 CSS,你会发现使用 css display: table 可以得到你正在寻找的布局。看看我的 fiddle ,让您朝着正确的方向前进。

...

http://jsfiddle.net/ben1/84Zgs/

关于javascript - css div动态问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com