CSS & HTML book for print - html

Okay, so hypothetically, let's say I wanted to write a book using HTML and CSS only. How would I go about defining a page header and footer (and have page numbers in the footer)? And how would I make it so that page breaks and margins show up in the browser (like a preview mode)?
I know it sounds like I'm asking for someone to just write the code for me, but I really just need direction to resources for something like this. I'm just completely stuck on how I would even begin to do something like this.
To explain what I want to show in the browser; I want to be able to see small versions of each page like you would in a PDF viewer, basically the text overflow would create a page-break:
I have looked into #media print, but that doesn't have any hooks for creating headers and footers.
and I can't get this to work (from w3.org):
title { position: running(header) }
#page { #top-center {
content: element(header) }
}
I have looked at the code from Boom!, and It's nice for printing, but it doesn't display in browser the same.
So... does anyone now where I could/should look for a good starting point for this?

This was my solution:
<div id='document'>
<div class='page'>
<div class='header'></div>
<div class='footer'></div>
<div class='content'></div>
</div>
</div>
Everything went in <div id='document'>. For each .page, the .header, .footer, and .content had the right height and width for a page.
After that, I used JavaScript to cut out everything that was overflowing outside the div.content. I then cloned div.page, updated the page number inside of the new page's header <div>, and filled the new page's content <div>.
This was repeated until I had like 100 pages and nothing was sticking out of the last page's content <div>.

I am assuming that you are using pure HTML and there is no code behind.
Because if there is any code behind then its a different story.
Define a main div having class="page". Inside that define 3 divs for header, content and
footer.
.page {
display: block;
height: 800px;
width: 100%;
/*Give margin as per your requirement.*/
}
.header {
display: block;
height: 50px;
}
.content {
display: block:
height: 700px;
}
.footer {
display: block;
height: 50px;
}
Add additional style as per your requirement.
create another style sheet with media type ="print"
There add the following style for page.
.page {
display: block;
height: 800px;
width: 100%;
/*Give margin as per your requirement.*/
/* this will print the page in new paper*/
page-break-after: always;
}
and the HTML for one page will look like this
<div class="page">
<div class="header">HEADER CONTENT</div>
<div class="content"> MAIN PAGE'S CONTENT</div>
<div class="footer"></div>
</div>
Repeat the above code an per the number of page you need.
You can also use table layout for this purpose.
And if you use code behind, then the content can be generated dynamically.
Hope this helps.

Well, it could be done by pure HTML and CSS but definitely not the way to go as it would become very frustrating to repeat blocks of code, almost the same, every time you wanted to start a new page. For the PDF like left panel you could use Iframes, more info here
basically, you would make a .htm page for every page of your book, strictly linked together by links, and when you would be finished, you could take a screenshot of every page you made, save the thumbnails, and make another html page that would be the panel, which would be eventually included (as the tutorial in my link shows) in all the other pages for the book.
UPDATE
Regarding page breaks, you could make div-s with the same class, and styled as pages, as shown here

Related

Can't get css with #media print to work properly

I am trying to make it so that when I try to print my page, the only thing that is printed is 1 long single div from that page.
After some research I figured out how to limit the browser to only print certain elements by using #media print, and setting visibility to hidden for the elements I do not want to show.
This is the css that I currently am using to accomplish this:
#media print {
html, body{
overflow-y: hidden;
}
body * {
visibility: hidden;
}
table {
float: none !important;
}
div {
float: none !important;
}
#PermitDetails, #PermitDetails * {
visibility: visible;
}
#PermitDetails {
position: absolute;
top: 0px;
left: 0px;
}
}
This code allows the PermitDetails div to display when printing, and hides any other elements (and the scrollbar) while printing.
This is the code for the PermitDetails div:
<div class="col-md-12 col-lg-10">
<div class="panel panel-default" id="PermitDetailsPanel">
<div class="panel-heading">
<strong>Permit Details</strong>
</div>
<div class="panel-body" id="PermitDetails">
</div>
</div>
</div>
This div is dynamically filled in based on options that the user selects on the page, so the size of it is always different.
The problem that I am having with this is that if I try to print the page, I do see only the div with the proper information, however there are a couple of things that are wrong:
Even though I have the div's position set as absolute, and left and top to 0, it still positions itself in the center of the page. I also noticed that it moves up or down based on where in the page I am currently scrolling to.
If I select enough information that the div fills up the page, the information does not move onto a second page to print. It just fills up the first page and gets cut off once it hits the bottom. This also moves around based on where I am scrolling on the page.
I read that this could be due to how bootstrap floats the columns, so I tried setting the div tags to float:none in the css (as seen above), but that did not change anything.
I'm really not sure what else the problem could be. Any help would be greatly appreciated. Let me know if more information is needed.

Using div class to contain an image using CSS

Hey guys i have a HTML/CSS related question here...
I'm developing on a salesforce application, which makes me use this apex tag to put images in and I'm not really comfortable with using them. I am making print layouts at the moment for some forms that i've created. Everything worked fine until i had 2 images that i needed to style differently. I have 1 image in the header and 1 image that is a box within the form. Since i am styling the image in the header with some padding and centering among other stuff...the other box image wont show up as i go to print. So i was wondering if i can just separate the header image via a div tag. Here is what i have so far....
HTML:
<div class="logo_print"></div>
CSS:
.logo_print{
float:left;
padding-left: 40px;
width: 64px;
height: 86px;
background-image:url('../css_images/seal2.png');
}
So this is the header image i put in a div tag...did not work but if anyone has any thoughts/solutions that would be great....been trying out a bunch of diff ways with no progress. Thanks
EDIT:
So I've put new CSS in with some recommendations..so now i see it on my website but when i go to print the forms...the image does not show up :/
OH and i am using #media print to put the CSS in
Reason it's not working is because you haven't specified a height and width in your css.
Try This:
.logo {
background-image: url('http://pixelative.co/wp-content/uploads/2014/06/logo2.png');
width: 209px;
height: 52px;
}
<div class="logo"></div>
Here's a codepen of the working example.
Hope this answers your question.

Bootstrap css: body not containing all elements on page

I have added Bootstrap Sass to a Rails project and I'm trying to redesign its home page. The issue I am facing is that the background style I have added to my <body> element only has effect on the part of the page that is initially visible upon loading the page. The page actually scrolls down to show additional elements, which are all enclosed in <body>. To solve this, I enclosed everything in <body> with a <div class="clearit"> .......</div>. In the CSS, I did two things: I first tried using the overflow:auto property, but that did not have the desired effect. I have also tried the following:
.clearit {
zoom: 1.0;
clear: both;
}
.clearit:after
{
zoom: 1.0;
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
overflow: auto;
}
Even with this, the browser seems to think that my <body> is simply the 100% of the part of the page that is initially visible upon loading, not the entire page till the bottom of the scroll bar. I have foraged through online solutions and guides, and tried multiple approaches for several days, but haven't yet found one that works. Any insight would be appreciated.
This may not be helpful, but are you trying to accomplish something like I've done here?:
http://www.danhendricks.com
Rather than setting the to 100%, I just set the top to height=100% and set the background image. See the .intro-section class here for an example:
http://www.danhendricks.com/wp-content/themes/single-page-modified/style.css
.intro-section {
background: url(images/my-background-image.jpg) no-repeat bottom center scroll;
height: 100%;
padding-top: 50px; /* So content isn't covered up by the header bar */
}
Though I don't have scrolling on this page, an easier to read example may be found here. It uses the exact same technique, just minus the header bar and and sections below the .intro-section:
http://www.nimbium.com
If I'm off base with what you are looking for, I apologize. I'm also new here so I apologize if this isn't a properly formatted response. I was just trying to offer some quick help.

.css columns for website navigation

I have something like the below for an electronic cigarette site I am designing:
<div id="top">
//code
</div>
<div id="nav">
//code
</div>
<div id="container">
//code
</div>
<div id="bottom">
//code
</div>
I want to structure it in a way that areas are defined by <div> tags and not by the contents themselves. Strictly speaking, things in a specific <div> element should be organized like the below:
I've tried things like float and it just looks tremendously ugly and text doesn't wrap properly. My first guess would have been to use css column properties but it splits the page into 2 parts with the bottom and top <div> elements being arranged above one or the other but never both.
I apologize if this is such a trivial task, but while I'm a pretty good logic programmer, css is not my strongest suit and it's something I generally devise through trial-and-error rather than rote memory or function.
The general spacing (ie. widths of <div> elements) is something I can accomplish, but just positioning things is something I'm at a loss about.
Here is the HTML:
http://pastebin.com/xbSypPcn
Here is the CSS:
http://pastebin.com/mZnBHPP0
Here is an image of what it looks like:
http://imageshack.us/a/img706/5117/uzbn.png
Here is an image of what I'd like it to look like: (excuse poor MSPaint work)
http://imageshack.us/a/img571/9219/uxm1.png
Excuse the very ugly site. I'd like to get the .css down before I furnish it to make it more aesthetically pleasing.
You should use something like this to accomplish your style task:
#top {
display: block;
height: 200px;
}
#left {
display: block;
width: 300px;
height: 500px;
float: left;
}
#right {
display: block;
width: 700px;
height: 500px;
float: right;
}
#bottom {
display: block;
height: 200px;
}
Combining the display: block with the right float and height and width settings should do the trick. I haven't tested this but the concept should help you get going in the right direction.
Additionally, you can nest div tags to get the desired text effect if the float is throwing this off.
For instance:
You may want HTML that looks like:
<div id="right">
<div id="right_content">
Your text here
</div>
</div>
edit/addition:
Thanks for adding your code HTML and CSS with the images is great! Since you are using a "liquid layout" % vs. px values... but you are still using px for your padding. I wonder if you took the padding values all out of the #contianer and #nav css styles it might fix it for you. It appears that you are very close now. You just need to trim the nav and container a bit so they look the way you are expecting them to look.
If you are using FF as a browser there is a great tool called Firebug that you can use to "inspect" your document. It will show you the html and corresponding HTML for whatever you point to. This tool has "saved my life" on many occasions.

Simple html/css layout? (two column)

I'm having a very hard time trying to come up with html/css for a layout to suite the following:
Where the left area is a static menu. The right area is dynamic content, generated using a call to ASP.Net's RenderBody method. You may not believe it, but I have been trying to figure this out for hours. I keep getting either the right section ending up underneath the left section taking 100% of the width or not displaying at all, with Chrome's object inspector saying its 0 pixels wide.
I feel like a complete idiot as this seems as if it should be easy as pie. Could I please get some help?
There's several ways to go about this. Here's one not particularly fancy but straight-up way to go about it:
<body>
<div id="menu">MENU</div>
<div id="content"> content <br /> content <br /> content </div>
</body>
CSS:
div { border: 2px solid black; } /* demo purposes */
#menu {
float: left;
width: 150px;
}
#content {
margin-left: 154px; /* menu width + (2 x menu.border-width) */
}
See this jsfiddle for a working sample.
This solution has the added benefit that your content region will take up exactly 100% of the remaining width of its parent:
<div class="parent">
<div class="content">blah...</div>
<div class="left-menu">blah...</div>
</div>
CSS:
.parent { padding-left:200px;width:100%; }
.content { position:relative;float:left;width:100%; }
.left-menu { position:relative;float:left;width:200px;right:200px;margin-left:-100%; }
Excellent tutorial on fluid layouts: http://www.alistapart.com/articles/holygrail
Works in IE7 and newer, Safari/Chrome/Opera/Firefox...
The best way to do this is by using the already considered safe to use box-sizing property.
Take a look at the tinkerbin -> http://tinkerbin.com/AcJjYk0r
It works as you want it to. Fixed width for the menu, percentage based width for the content area.
Then...
...if you want the background-colors to expand to the highest of the heights between the two boxes (remember, one times the menu can be higher than the content box, and vice-versa), then the only way to go about it (no javascript) is to use a background image and place it below the two boxes. With css3 gradients (safe to use too) it's pretty easy. Take a look:
http://tinkerbin.com/3ETH28Oq