Creating a grid of boxes to fill the browser width and wraps nicely (when the browser is resized), can be achieved by using the inline-block value of the display property. Inline-block elements are like inline elements but they can have a width and a height. Notice that no clear property is needed, like we used in the old way:
HTML file: | Displayed by browser: |
---|---|
<style>
.floating-box { display: inline-block; width: 150px; height: 75px; margin: 10px; border: 3px solid #8AC007; } .after-box { border: 3px solid red; } </style> <body> <h2>The New Way - using inline-block</h2> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="after-box">Another box, after the floating boxes...</div> </body> |
The New Way - using inline-blockFloating box
Floating box
Floating box
Floating box
Floating box
Floating box
Floating box
Floating box
Another box, after the floating boxes...
|