Is it possible to print a different footer on every page? - html

I'm converting an Access application to web, and need to print reports from it. These are letters mailed out and so the bottom of the letter, which is the 'please return' portion, will always be at the bottom of the page, regardless of how big the body of the letter is. I've used DIVs to lay out the letters and mimicked Access quite well, but I don't know how to get each letter's header at the bottom of its page. Using the CSS position: fixed; for the footer just makes every footer show up at the bottom of every page, and we would like to be able to print off multiple letters at once.
If I remove the fixed, it does display each footer on its own page, they weren't aligned to the bottom of it.
Can I have my cake and eat it too? Doesn't need to be cross-browser, and I'll move to PDF if absolutely necessary, but what are my options in CSS/HTML? Somehow converting it all to a table and trying out tfoot? But will that enforce it to be at the bottom of each page?
Edit: A sample of the CSS/HTML:
.reportcontainer {
width: 100%;
page-break-inside: avoid;
page-break-after: always;
position: relative;
}
.reportbody {
float: left;
text-align: left;
}
.reportfooter {
width: 100%;
float: left;
bottom: 0;
position: fixed;
}
<div class="reportcontainer">
<div class="reportbody">
yadda yadda yadda
</div>
<div class="reportfooter">
stuff goes here
</div>
</div>

Try this. I've had to figure out a lot of html printing lately as well. You can figure out how you want to replicate the divs, either backend or using jquery cloning for each report. Borders are just to illustrate containers.
.reportcontainer {
width:8.5in;
height:11in;
page-break-inside:avoid;
page-break-after:always;
border:1px solid red;
}
.reportbody {
width:100%;
height:10in;
border:1px solid yellow;
}
.reportfooter {
width:100%;
height:1in;
border:1px solid blue;
}
</style>
<div class="reportcontainer">
<div class="reportbody">
yadda1 yadda1 yadda1
</div>
<div class="reportfooter">
footer 1 goes here
</div>
</div>
<div class="reportcontainer">
<div class="reportbody">
yadda2 yadda2 yadda2
</div>
<div class="reportfooter">
footer 2 goes here
</div>
</div>
<div class="reportcontainer">
<div class="reportbody">
yadda3 yadda3 yadda3
</div>
<div class="reportfooter">
footer 3 goes here
</div>
</div>

I would recommend using PDF. If you need that level of control for printed material, you're going to be fighting to get HTML to work across browsers and this is really what PDF is designed for.
tfoot would not help, it only ensures that the footer is at the bottom of the table, not the bottom of the page.

Related

How do i use #media print queries with a dynamic web page? All i'm getting is a blank page currently

I have a dynamic web page that is generated when a user clicks to view more details on a car. I basically want a button that says 'Print Details' so the customer can print the vehicle details, but I don't want it to print the header and footer just the bits in the middle. So I currently have (without pasting allll my code) a div with my header and a div with my footer. Then I have a section tag using the class's 'section white'. When the user clicks print, I want to print JUST the section tag and everything inside it. However currently when I've tried this I just get a blank page..
This is the code I'm currently using to try and do it.
<style type="text/css">
#media print {
body * {
visibility: hidden !important;
}
.section .white {
visibility: visible !important;
height: 100%;
width: 100%;
position: fixed;
background-color: blue;
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
z-index: 9999999;
}
}
</style>
I won't paste my HTML page, only because it's a lot of code but the structure looks like this.
<html>
<body>
<div class="header">
</div>
<section class="section white">
</section>
<div class="footer">
</div>
</body>
</html>
body * {
visibility: hidden !important;
}
This hides everything inside the body.
.section .white {
visibility: visible !important;
}
This unhides anything with class="white" that is a descendant of anything with class="section".
You aren't selecting the section
<section class="section white">
The only element with class="white" is the same element as has class="section". It is not a descendant of it.
Remove the descendant combinator:
.section.white {}
You have no content to print
<section class="section white">
</section>
There's nothing to see. You have to have some content for it to show up!
If you did have content, then any elements would still be hidden
body * would match them and hide them.
Just hide the elements you need to hide, and nothing else. Use selectors that actually match them.
Write semantic markup while you are at it. Don't use classes which match element types, either use better class names or the actual element types.
Avoid !important, it is almost always more trouble than it is worth.
body > :not(section):not(.white) {
visibility: hidden;
}
<header>
This is the header
</header>
<section class="white">
<p>This is a section</p>
<p>...</p>
</section>
<footer>
This is the footer
</footer>

HTML/CSS: How to fix a header in the center

HTML/CSS newbie here. I am making a web page with a text header in the top center of the page and a login button on the upper right. I'm writing in Bootstrap using React (which uses embedded HTML). Here is the code.
Header:
<div className="page-header">
<h1 id="header">Header text</h1>
</div>
Login button:
<div id="login">
/*Displays login button if user is logged in, 'Welcome, user' if not*/
{this.state.loggedIn?
<div className="welcomeText">
<p>Welcome, {this.state.user}</p>
</div> :
<div>
<button id="loginButton" onClick={this.onClick}>Login</button>
</div>
}
</div>
CSS:
#header {
text-align:center;
}
#login {
float:right;
}
.welcomeText {
float:right;
}
The issue is that the login button is pushing the header text to the left and I have no way to move it back. I can temporarily solve this using padding; however, when the login button is replaced by a username, it gets pushed over even further the longer the username is. I'd like to know how I can fix this so that the username will be right-aligned and the header will stay in place. Thanks in advance!
As you write in it seems it may be react or something like javascript jsx format.
for header fix you should have to write code like below. this below given code is just to fix header at top position as per your need.
.page-header{
position:fixed;
top:0;
width:100%;
}
I'd use absolute positioning. I've simplified the example but you should get a good idea.
HTML
<div id="page-header">
<h1 id="header">Header text</h1>
<div id="login">
<div className="welcomeText">
<p>Welcome, Test User</p>
</div>
<div>
<button id="loginButton">Login</button>
</div>
</div>
</div>
CSS
#page-header {
background-color: #f0f0f0;
padding: 1em;
position: relative;
text-align: center;
}
#login {
position: absolute;
right: 1em;
top: 1em;
}
Set position: relative on #page-header so that the child element is positioned relative to it rather than the page. Then set position: absolute on the #login element. If you set its right position it will always sit to the right of the centralised #header text.
As long as you apply to absolute position to the #login element the size of the children won't matter. You'll probably need to tweak this on smaller devices, though, as there will be text overlapping.
https://codepen.io/raptorkraine/pen/QBdbPy

How can I bring a div above the current front-most (z-index: 0) div?

I'm building a gauge which uses pure CSS. It has a background to clip the remainder of the progress colour from showing. I want to add another div on top which gives a text indication of the progress: "10%".
It seems like no matter what I do, I end up with the background clip covering my text.
I've got an example of the problem here:
https://svelte.technology/repl?version=1.60.3&gist=77e1b55c23e229dee8d45b5648610593
An extremely cut down version of my code, demonstrating the problem is as follows:
<div class="gauge-wrap">
<div class="gauge-core">
<div class="gauge-bg" style="background-color: #fff;">
<div class="gauge-bg-value">10 %</div>
</div>
<div class="gauge-cap" style="background-color: #000;"></div>
</div>
</div>
<script>
.gauge-bg-value {
position: relative;
color: #f0f;
top: 7px;
z-index: 6;
}
.gauge-wrap {
position:relative;
margin:0 0 20px;
}
.gauge-bg {
position: absolute;
width: 200px;
height: 200px;
border-radius:100px;
z-index:0;
}
.gauge-cap {
position: absolute;
top:16px;
left:16px;
width: 168px;
height: 168px;
z-index:5;
}
</script>
It seems like z-index: 0 is still on top of my text div (.gauge-bg-value), even though I've given it a higher index.
Update - Solution:
In building my example, I moved the text into the .gauge-cap div and now it sits on top. Perhaps it was that div covering it all along. Happy to hear solutions that don't modify the structure of the html though.
This is to do with stacking context. In a case like this...
<div class='foo'>
<div class='bar'></div>
</div>
<div class='baz'></div>
...if foo and baz both create stacking contexts, and baz has a higher z-index than foo, then bar can never appear above baz no matter what. You'll have to break your markup apart into different layers instead (though in your example, I think you'd have an easier time using SVG instead of HTML).

Keep images from breaking to next line without float

I have a footer with social media icons. I want the icons arranged in a 3 x 3 grid
like below.
# # #
# # #
# # #
I also want it centered in a div. The issue that I'm running into, is that when I float the elements left to keep them on the same line my
margin-left:auto;
margin-right:auto;
Doesnt work, and they just align left. I need a solution that will work for mobile since my whole site is responsive.
Here is the HTML
<div class="d-all m-all" id="mainFooter">
<div class="d1-d4 m-all" id="socialMedia">
<div id="centerIcons">
<img src="images/fb_icon_vi.png"><img src="images/tw_icon_vi.png"><img src="images/in_icon_vi.png">
</div>
</div>
<div class="d5-d8 m-all" id="contact">
Contact
</div>
<div class="d9-d12 m-all" id="awards">
awards
</div>
</div>
And here is the CSS
#mainFooter{
background-color:black;
height:250px;
}
#socialMedia{
background-color:green;
}
#socialMedia img{
display:block;
}
#centerIcons{
background-color:yellow;
width:50%;
margin-left:auto;
margin-right:auto;
height:75px;
}
#centerIcons img{
margin-left:auto;
margin-right:auto;
}
The whole site can be seen HERE
I guess you want to something like this, right?
#socialMedia img {
display: inline-block;
}
#centerIcons{
background-color:yellow;
width:50%;
height:75px;
max-width: 171px;
margin: 0 auto;
}
#centerIcons img{
/* nothing is needed */
}
Explanation:
display: inline-block; will keep as block but not opening a new line
since #centerIcons is a DIV element, it is a block element, to make use of centering effect with margin: 0 auto; a width control is needed
so max-width: 171px; will constraint its width to a maximum of 171px (icon width 57px * 3), you may adjust as you need
Note:
About display property, please refer to W3C's visual formatting model.
About box model specification, you may refer to W3C's box model.
Depends on your browser compatibility plan, max-width does not supported in IE8 below and IE8 have some bugs. For details, you may refer to online compatibility chart like this.
If you are using jQuery and really mean to support IE6-8, you may consider using polyfill such as Scott Jehl's Respond.js
Edit: I think #Matt Smith's answer is what you want, I may have misinterpreted your meaning. Anyway, for your reference.
<img> is a replaced inline element (by default). The image elements sit beside each other like words. Therefore there's no need to change their display type to block (as you have done in the live demo).
I want the icons arranged in a 3 x 3 grid
In order to achieve that, you could wrap each 3 images by a wrapper, and add text-align: center to that element to align the inline images horizontally.
EXAMPLE HERE.
<div id="centerIcons">
<div class="wrapper">
<img src="images/1.png">
<img src="images/2.png">
<img src="images/3.png">
</div>
<div class="wrapper">
<img src="images/4.png">
<img src="images/5.png">
<img src="images/6.png">
</div>
<div class="wrapper">
<img src="images/7.png">
<img src="images/8.png">
<img src="images/9.png">
</div>
</div>
.wrapper {
text-align: center;
}
Add text-align: center to the #centerIcons {} rule and display: inline-block to your #centerIcons img {} rule:
#centerIcons img {
text-align: center;
}
#centerIcons img {
display: inline-block;
}

A clean CSS3 3-column layout, where to start?

I'm currently updating a pretty old website (last update was around 2001), and have agreed to use HTML5 and CSS3.
For the general design, I'm working on a very clean white and gray tones style, with many paddings and margins. My problem resides in the home page: I'd like to have a 3-column centered layout. But where to start? I've tried some floating, but in vain.
Am I doing this right ?
HTML:
<div class="colwrapper">
<div class="ltcol"></div>
<div class="ctcol"></div>
<div class="rtcol"></div>
</div>
CSS:
.colwrapper { width:1020px; }
.ltcol, .ctcol, .rtcol { width:300px; margin:0 10px; padding:10px; }
.ltcol { float:left; }
.ctcol { margin-left:340px; }
.rtcol { float:right; }
your css should be like this:
.ltcol, .ctcol { float:left; }
.rtcol { float:right; }
The purpose of the CSS float property is, generally speaking, to push a block-level element to the left or right, taking it out of the flow in relation to other block elements. This allows naturally-flowing content to wrap around the floated element. This concept is similar to what you see every day in print literature, where photos and other graphic elements are aligned to one side while other content (usually text) flows naturally around the left- or right-aligned element.
For More details you must have to read this intresting article.
See This Demo: http://jsfiddle.net/akhurshid/YRWLV/
Your HTML is very clean - this is a great step forward.
You need to add a float: left to all the columns. To ensure the float is cancelled after your columns, it is best to add a clear div after the floated columns.
HTML:
<div class="colwrapper">
<div class="ltcol">Column 1</div>
<div class="ctcol">Column 2</div>
<div class="rtcol">Column 3</div>
<div class="clear"></div>
</div>​​​​​​​​​​​​​​​​​
CSS:
.colwrapper { width:1020px; }
.ltcol, .ctcol, .rtcol { width:300px; margin:0 10px; padding:10px; background-color: #efefef }
.ltcol { float:left; }
.ctcol { float:left; }
.rtcol { float:left; }
.clear { clear: left; }
​
So you add css3 tag for this questio so I suggest you to make this with css3 column layout:
More info
for example
HTML
<div class="colwrapper">
<div>text</div>
</div>
CSS
.colwrapper div
{
-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
column-count:3;
}
It does not work on IE.
Use one of these tried and tested implementations instead of rolling out your own. In addition to the fact that you'll be getting tested and working code, you'll add responsiveness to your site with almost zero effort.
http://cssgrid.net/
http://960.gs/
http://framelessgrid.com/
http://goldengridsystem.com/
and lots more if you google..
could also use Flexbox property for this now as well so you don't need to worry about floats or clearfix's.
main{
/* .colwrapper{ */
display: flex;
flex-flow: row;
justify-content: center;
}
main > section{
/* .ltcol,.ctcol,.rtcol{ */
display:flex;
flex-flow:column;
align-items:center;
padding:10px; padding:.625rem;
}
main > section:nth-child(2){
/* .ctcol{ */
margin:0 20px; margin:0 1.25rem;
}
http://caniuse.com/flexbox shows the support for it isn't quite as far along as you would probably like, however, there are ways to improve support by mixing old versions of the syntax with the new http://css-tricks.com/using-flexbox/ has a great write up on it from Chris Coyier if you want to play with this for a next project (this post is fairly old). You can also get more details at http://html5please.com/#flexbox
Also, if you're using HTML5 I'd probably go with sections over divs for a more semantic structure, so a comparison would look something like this:
<main>
<section></section><!-- or <nav></nav> -->
<section></section><!-- or <article></article> -->
<section></section><!-- or <aside></aside> -->
</main>
instead of...
<div class="colwrapper">
<div class="ltcol"></div>
<div class="ctcol"></div>
<div class="rtcol"></div>
</div>
Just try putting the rtcol div beofre le ltcol div.
<div class="colwrapper">
<div class="rtcol">X</div>
<div class="ltcol">X</div>
<div class="ctcol">X</div>
</div>​
http://jsfiddle.net/EDjpy/