Reputation: 199
This is what I have:
<style>
div.box {
width:400px;
height:200px;
float:left;
}
</style>
<div style="width:100%; height:200px; overflow:hidden;">
<div style="width:2000px; height:200px;">
<div class="box" style="background:red;"></div>
<div class="box" style="background:blue;"></div>
<div class="box" style="background:yellow;"></div>
<div class="box" style="background:orange;"></div>
<div class="box" style="background:black;"></div>
</div>
</div>
As the page is resized, I want the contents of the 2000px div to stay centered, so the yellow colored div is always in the middle of the screen.
Is it possible to do this with only css?
Upvotes: 1
Views: 1204
Reputation: 1942
<div style="width:100%; height:200px; overflow:hidden;">
<div style="width:2000px; height:200px;position: relative; left: 50%; margin-left: -1000px">
<div style="width:400px; height:200px; float:left; background:red;"></div>
<div style="width:400px; height:200px; float:left; background:blue;"></div>
<div style="width:400px; height:200px; float:left; background:yellow;"></div>
<div style="width:400px; height:200px; float:left; background:orange;"></div>
<div style="width:400px; height:200px; float:left; background:black;"></div>
</div>
</div>
Upvotes: 7