【发布时间】:2014-12-17 04:00:24
【问题描述】:
所以我尝试了很多将 div 1 的高度调整为 div 2(或相反)。尝试过表格,尝试过 javascript(工作但在调整大小时弄乱了布局,请参阅:1)等等。
所以;我有这个设计,我试图让它响应。这似乎没问题,但是当我的屏幕尺寸大于 1024 像素时,我的 rightCol2 div 没有扩展到 leftCol2 div(反之亦然)。我有点剥离我的布局以使其尽可能短和干净,我想知道是否有人可以帮助我解决这个问题,以便 leftcol2 和 rightCol2 div 调整到彼此的高度,并且布局保持响应没有任何问题。我的代码在这里:http://jsfiddle.net/53wn4fzg/ 或在下面查看。
这花费了我很多时间,非常感谢您的帮助!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
body{ background:#f6f6f6;}
#mainContent2 {
clear: left;
text-align:justify;
}
#container2 {
padding-right:1%;
width:97%;
margin: 10px auto;
position: relative;
padding-top: 10px;
max-width: 927px;
}
#leftCol2{ float: left;
width: 180px;
padding: 15px 0px 15px 15px;
margin-top: 50px;
background: #fff;
-moz-border-radius-topleft: 4px;
border-top-left-radius: 4px;
min-height: 400px;
position: relative;
}
#rightCol2{float:right;
width:732px;
background: #fff;
-moz-border-radius-topleft: 4px;
border-top-left-radius: 4px;
-moz-border-radius-topright: 4px;
border-top-right-radius: 4px;
padding: 0px;
min-height: 480px;
height:100%;
position: relative;
}
#footer2 {
clear: both;
background: #FFFFFF;
max-width: 712px;
width: 100%;
margin-left: 195px;
background: #FFFFFF;
padding: 10px 10px;
}
#topBar2{
-moz-border-radius-topleft: 4px;
border-top-left-radius: 4px;
-moz-border-radius-topright: 4px;
border-top-right-radius: 4px;
background: #f7f3f0;
margin-top: 0px;
float: left;
width: 100%;
padding: 0px;
min-height:50px;
}
div#primarycustom{display:none;}
.shadow3 {
-moz-box-shadow: -1px -1px 2px #ccc;
-webkit-box-shadow: -1px -1px 2px #ccc;
box-shadow: -1px -1px 2px #ccc;
}
@media only screen and (max-width: 1024px) {
.shadow2, .shadow3 {
-moz-box-shadow: 0 0 0 2px #ccc;
-webkit-box-shadow: 0 0 0 2px #ccc;
box-shadow: 0 0 0 2px #ccc;
}
#logo h1#site-title {margin-left: 10px !important;}
#leftCol2{float:left; margin:10px 0 0 1%; padding:0;
width:100%;
-moz-border-radius-topright: 4px;
border-top-right-radius: 4px;
}
#rightCol2{float:left;margin:0 0 0 1%; padding:0;
width:100%;
}
#container2 {padding-right:1.7%; width:97%;}
#rightCol2, #leftCol2, #footer2{width:100%; }
div#logo{width:100%; position:relative; top:0; left:0;}
#topBar2{width:100%;}
#footer2 {width:100%;
-moz-border-radius-bottomleft: 4px;
border-bottom-left-radius: 4px;
-moz-border-radius-bottomright: 4px;
border-bottom-right-radius: 4px;
margin:10px 0 10px 1%;
padding:10px 0 10px 0;
max-width:none;
float:left;
}
h1#site-title {float:left;}
div#primarycustom { margin:0 0 10px 0;display:block; float:left;}
div#primarycustom div#custom2 { width: 70% ;
margin-left: auto ;
margin-right: auto ;
margin-top:10px;
display:block;}
}
</style>
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>//<![CDATA[
$(function(){
$(window).resize(function() { //Fires when window is resized
var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
if(width <= 1024) {
$("#container2").each(function() {
var detach = $(this).find("#leftCol2").detach();
$(detach).insertAfter($(this).find("#rightCol2"));
})
}
else {
$("#container2").each(function() {
var detach = $(this).find("#rightCol2").detach();
$(detach).insertAfter($(this).find("#leftCol2"));
})
}
});
});//]]>
</script>
</head>
<body>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div id="container2">
<div id="logo">
<h1 id="site-title">
Here my site title
</h1>
<div id="primarycustom" role="complementary">
<div id="custom2">
<select style="max-width:100%;" onChange="if (this.value) window.location.href=this.value">
<option>option 1</option>
<option>option 2 </option>
</select>
</div>
</div><!-- #primary .widget-area --> </div>
<div id="leftCol2" class="shadow3">
<div class="custpad">
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
<p>This sidebar is longer than my mainContent2 div on the right.</p>
</div>
</div>
<div id="rightCol2" class="shadow3">
<div id="topBar2">
Slogan
</div>
<div id="mainContent2">
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p><p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer.</p>
<p>Here is my main content of my site. The sidebar in this is case is longer(last).</p>
</div>
</div>
<div id="footer2" class="clearfix shadow2">
<div id="colophon">
<div id="site-info">
Here my footer
</div>
</div><!-- #colophon -->
</div>
</div>
</body>
</html>
【问题讨论】: