Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alignment issues while printing Avery 5160 labels

Tags:

html

css

printing

I am trying to print bunch of data here is my css for Avery 5160 labels

body {
    width: 8.27in;
    margin: 0in .2in;
}
.label {
    /* Avery 5160 labels */
    width: 3.24016in; /* plus .6 inches from padding */
    height: 1.381in; /* plus .125 inches from padding */
    padding: .125in 0 .05in .3in;
    margin-right: .515in; /* the gutter */

    float: left;

    /* text-align: center; */
    overflow: hidden;

    outline: 1px dotted;  /*outline doesn't occupy space like border does */
}

The problem is if i print 16 labels i.e 1 page it comes out nicely. But if it goes to page 2 bottom labels kind of crops and messes page 2.

my test code in php

$max = 15; // if max then 15 :/ i cri
 $str1 = "<b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958";
for ($i=0; $i <= 16; $i++) { 
 echo'<div class="label">'. $str1.'</div>';
}

script for printing

var t;
function prt()
{
    clearTimeout(t);
    window.print();
}
t=setTimeout("prt()",1000);

Attaching SS Attaching SS

Attaching full source Source

like image 421
Bender Avatar asked Dec 21 '25 13:12

Bender


1 Answers

On my preview it looks difference if I print. I think this has to do with the margin of the printer.

Anyway, I change your float:left; to display:inline-block and add a page break after 14 elements. Does this work for you?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Artpro</title>
<style>
body {
    width: 8.27in;
    margin: 0in .2in;
}
.label {
    /* Avery 5160 labels */
    width: 3.24016in; /* plus .6 inches from padding */
    height: 1.381in; /* plus .125 inches from padding */
    padding: .125in 0 .05in .3in;
    margin-right: .515in; /* the gutter */

    display: inline-block;

    /*text-align: center;*/
    overflow: hidden;

    outline: 1px dotted;  /*outline doesn't occupy space like border does */
}
@media all {
    .page-break { display: none; }
}

@media print {
    .page-break { display: block; page-break-before: always; }
}
</style>

<script>
    var t;
    function prt()
    {
        clearTimeout(t);
        window.print();
    }
    t=setTimeout("prt()",1000);
</script>

</head>

<body>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
    <div class="label"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>

    <div class="label page-break"><b>Title </b></br>Fname Lname</br>Media Type</br>200x500 cm</br>1958</div>
</body>
</html>
like image 145
Markus Avatar answered Dec 23 '25 03:12

Markus