After extensive searching on Google and StackOverflow, I have yet to find a solution to my issue. My question is, how can I ensure that when the browser reaches a certain breakpoint, the mainleft
div with left float moves underneath the mainright
div with right float?
Unfortunately, this stackoverflow thread discussing the priority of floating divs did not provide a solution for me: Responsive CSS div positioning priority
You can view my problem on jsfiddle at the following link:
https://jsfiddle.net/jamshidi/8ahb03qn/1/
Html:
<div class="maincontainer">
<div class="mainleft">
mainleft
</div>
<div class="mainright">
mainright
</div>
</div>
<footer>
<div class="footer-end">
footer
</div>
</footer>
CSS:
.maincontainer{
height:auto;
width: 700px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
background-color: red;
overflow: hidden;
}
.mainleft{
float: left;
width: 200px;
height:auto;
background-color: #D0D1F9;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
}
.mainright{
float: right;
width: 500px;
height:auto;
background-color: #C4F4D6;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
}
.footer-end{
height:35px;
width: 700px;
background-color: #bb0700;
color:#fff;
padding-right: 0px;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
clear:both;
}
@media screen and (max-width: 500px) {
.mainleft{
float: none;
width: 100%;
height:auto;
background-color: #D0D1F9;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
}
.mainright{
float: none;
width: 100%;
height:auto;
background-color: #C4F4D6;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
margin-bottom: 0px;
}
}