Consider two container elements side by side, both of them are longer than the width of the viewport and the viewport is scrollable horizontally. Both of them contain an element inside that I want to keep in the center of visible portion of the containing div. Here is the markup:
<body>
<div class="wrapper">
<div class="container" id="container1">
<div class="element" id="element1"></div>
</div>
<div class="container" id="container2">
<div class="element" id="element2"></div>
</div>
</div>
</body>
and here is the css:
body {
overflow-x: auto;
}
.wrapper {
width: 400%;
}
.container {
width: 50%;
border: 1px solid #ccc;
height: 50px;
float: left;
}
I am very sorry I find it very difficult to describe what I need since English is not my native language but I would like to describe it with an image and an animation: