@media
In one approach, you can use the media css rule:
.left{ float: left; } .right{ float: right; } @media all and (max-width:720px) { .right,.left { float:none; } }
<div class='parent'> <div class='left'>This should be on the left</div> <div class='right'>And this should be on the right :)</div> </div>
bends
Otherwise, you can use flex (not fully compatible with all browsers right now):
.parent { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; } .left, .right{ -webkit-flex: 1; flex: 1; min-width: 400px; border: 1px solid #555; }
<div class='parent'> <div class='left'>This should be on the left</div> <div class='right'>And this should be on the right :)</div> </div>
flex + js
Javascript used to achieve proper text alignment.
function adjustRight() { var right = document.getElementsByClassName("greenright")[0]; var left = document.getElementsByClassName("greenleft")[0]; if (left.offsetLeft == right.offsetLeft) { right.style.textAlign = "left"; } else { right.style.textAlign = "right"; } } window.addEventListener("load", adjustRight); window.addEventListener("resize", adjustRight);
.parent { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; } .greenleft, .greenright{ -webkit-flex: 1; flex: 1; min-width: 400px; border: 1px solid #555; }
<div class='parent'> <div class='greenleft'>This should be on the left</div> <div class='greenright'>And this should be on the right :)</div> </div>
Js
This example is fully consistent with javascript:
function adjustRight() { var right = document.getElementsByClassName("greenright")[0]; var left = document.getElementsByClassName("greenleft")[0]; if (left.offsetTop == right.offsetTop) { right.style.float = "right"; } else { right.style.float = "left"; } } window.addEventListener("load", adjustRight); window.addEventListener("resize", adjustRight);
.greenleft{ float: left; } .greenright { float: right; }
<div class='parent'> <div class='greenleft'>This should be on the left</div> <div class='greenright'>And this should be on the right :)</div> </div>
source share