html - CSS page-break-after and float not playing nicely? -


if have following html code:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"     "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>         <meta http-equiv="content-type" content="text/html;charset=utf-8"/>         <title>test</title>     </head>     <body>         <div style="page-break-after: always; float: left;">hello</div>         <div style="page-break-after: always; float: left;">there</div>         <div style="page-break-after: always; float: left;">bilbo</div>         <div style="page-break-after: always; float: left;">baggins</div>     </body> </html> 

i want 1 word printed on each page, page break after each one. (this simplified code - in actual web page, floats important.)

firefox prints fine, both ie , safari print them on 1 page, ignoring page breaks. bug in browsers? there better way this?

thanks.

it floats messing printing.

do need floats there printing? or floats needed web?

why asking can have different css classes different medias (print, screen) http://www.w3.org/tr/css2/media.html

so float can on screen media - show web. while want page break show print media.

here example using media: (note when referencing css can choose media via attribute )

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"   "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">   <head>     <meta http-equiv="content-type" content="text/html;charset=utf-8"/>     <title>test</title>     <style>         @media print {        .mydiv { page-break-after: always; }       }       @media screen {         .mydiv {float:left;}       }     </style>     </head>   <body>     <div class="mydiv">hello</div>     <div class="mydiv">there</div>     <div class="mydiv">bilbo</div>     <div class="mydiv">baggins</div>     </body>   </html> 

update:

will work need? gives 3x3 on each page when printing out. on screen it's 3x6. quick sample.

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"   "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">   <head>     <meta http-equiv="content-type" content="text/html;charset=utf-8"/>     <title>test</title>     <style>             .break         {                    page-break-after: right;                     width:700px;                    clear:both;         }         .mydiv {             float:left;         width:200px;         height:100px;         background-color:blue;         margin:5px;         }       }     </style>     </head>   <body>     <div class="break">         <div class="mydiv">1</div>         <div class="mydiv">2</div>         <div class="mydiv">3</div>             <div class="mydiv">4</div>         <div class="mydiv">5</div>         <div class="mydiv">6</div>             <div class="mydiv">7</div>         <div class="mydiv">8</div>         <div class="mydiv">9</div>       </div>      <div class="break">         <div class="mydiv">11</div>         <div class="mydiv">22</div>         <div class="mydiv">33</div>            <div class="mydiv">44</div>         <div class="mydiv">55</div>         <div class="mydiv">66</div>            <div class="mydiv">77</div>         <div class="mydiv">88</div>         <div class="mydiv">99</div>      </div>     </body>   </html> 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -