2

Here is what my print page look like,

enter image description here

Here is my html glimpse,

<style>
    .container{
        float: left; 
        border: 1px solid Black; 
        width: 400px;
        height: 350px;
        margin: 10px;
        padding: 10px;
        page-break-inside: avoid;
    }
    .container img{
        max-width: 200px;
        max-height: 200px;
    }
</style>
<div class="container">
    <b>Name: </b>@Product.Name<br />
    <b>Model: </b>@Product.ModelNumber<br />
    <img src="@Product.ImagePath" /><br />
    <span style="font-size: 20px">DetailedDescriptions</span><br />
    @foreach(var attr in Product.DetailedDescriptions){
        @attr.Header<br />
    }
    <span style="font-size: 20px">KeyAttributes</span><br />
    @foreach(var attr in Product.KeyAttributes){
        @attr.Name<br />
        @attr.Value<br />
    }
</div>

How to make sure that the page break after every 6 divs using css

Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322

3 Answers3

4

You should encapsulate your divs and create a better structure of this type in HTML:

<body>
    <div class="container-holder">
        <div class="container-row">
            <div class="container"></div>
            <div class="container"></div>
        </div>
        <div class="container-row">
            <div class="container"></div>
            <div class="container"></div>
        </div>
        <div class="container-row">
            <div class="container"></div>
            <div class="container"></div>
        </div>
    </div>
    <div class="container-holder">
        <div class="container-row">
            <div class="container"></div>
            <div class="container"></div>
        </div>
        <!-- keep adding more container-rows -->
    </div>
</body>

Then in CSS take several things into account:

  1. let body take up whole page
  2. use page-break-inside: avoid;
  3. give specific width and height in pixels to divs
  4. containers should have the display: inline-block and vertical-align: bottom;
  5. container-holders should have display:block property
  6. [bonus] avoid inline style

Here is a working jsFiddle

I have tried it outside of jsFiddle and I get this result:

print preview

achudars
  • 1,486
  • 15
  • 25
3

You can use

div:nth-of-type(6n) {
    page-break-after:always;
}

to insert a page-break after each 6. div, but I think this will not work with floats.

Roland Jansen
  • 2,733
  • 1
  • 16
  • 21
1

You could do it this way:

FIDDLE

.wrapper div:nth-child(6n)
{
    margin-bottom: 300px;
}

Which means: after every 6 containers - add a bottom margin of x px (how ever much you need) so that it pushes the next boxes to the next page.

Danield
  • 121,619
  • 37
  • 226
  • 255