Reputation: 5079
I am trying to do some step by step (4 steps in total) checkout. I thought about having a kind of a horizontal slider setup.
I created a container with a width of 400% containing 4 containers. These containers should be side by side and fill 100% of the Window. This is kind of a horizontal slider but i want to use it as a form.
[[[Container 1][Container 2][Container 3][Container 4]]]
My html:
<div class="container fullWidth">
<div id="checkoutContainer">
<div class="checkout" id="cart">Cart</div>
<div class="checkout" id="contact">Contact</div>
<div class="checkout" id="address">Addresse</div>
<div class="checkout" id="overview">Übersicht</div>
<div class="checkout" id="thankyou">Danke</div>
</div>
</div>
My CSS:
.container.fullWidth {
width : 100%;
overflow-x: hidden;
}
div#checkoutContainer {
background-image: url(../img/background.jpg);
background-repeat : repeat-x;
width : 500%;
height : 657px;
}
div#checkoutContainer div.checkout {
float : left;
width : 900px;
height : 657px;
}
The question is now: Can i somehow make the single divs fill the width of the page without using javascript (I know i can detect the page width and set the width)? Setting div.checkout { width : 100% }
does not work as they will stack on each other then.
Upvotes: 1
Views: 4532
Reputation: 54629
Check out my approach, divs will fill the container so no need to 'fine tune', plus it is responsive and not dependent on the number of divs
HTML
<div id="checkoutContainer">
<div class="checkout" id="cart">Cart</div>
<div class="checkout" id="contact">Contact</div>
<div class="checkout" id="address">Addresse</div>
<div class="checkout" id="overview">Übersicht</div>
<div class="checkout" id="thankyou">Danke</div>
</div>
CSS
#checkoutContainer {
overflow: hidden;
white-space: nowrap;
width: 100%;
}
.checkout {
display:inline-block;
width : 100%;
height : 200px;
vertical-align: top;
}
Upvotes: 6
Reputation: 3155
Quick Example: http://jsfiddle.net/DTTnB/
You can fine-tune this how you want
I took off overflow-x: hidden
so you can see that they lie horizontally
.
you were on the right track
Key differences:
I made each of the containers only a proportion of their wrapping container:
.checkout:
width : 20%;
Their wrapping container I made it wide enough to accommodate all containers so that each container would take up at least the page width.
checkoutContainer:
width : 1000%;
you can fine tune this
Upvotes: 4