css pdf page - header overlapping with content - html

As we can see from the image my content overlaps with the header image and this is the code I have:
<style type="text/css" media="print">
#page {
/*size:landscape;*/
#top-center {
content: element(header);
}
#bottom-left {
content: element(footer);
}
}
div.header {
padding: 10px;
position: running(header);
}
div.footer {
display: block;
padding: 5px;
position: running(footer);
}
.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>
<div class="header">
<img src="logo.png" title="logo" width="200px"/>
</div>
<div class="content">
</div>
P.S.: Please don't close this question as duplicate as I have already searched all the questions related to the same but mine looks different as PDF is involved.

Headers and footers are established within the page margins.
So the solution is to increase the page top margin, for example:
#page {
margin-top: 50mm;
}

Method to implement header footer properly in PDF
After finding a lot on internet on different solutions and workaround, I'm finally sharing a way that works for me.
Please add these style to report container (the div in which report is rendered).
<div #scrollingContainer class="col-xxs-9 content-container" style="overflow-x: hidden;width:100%;">
</div>
// Div properties may differ
Wrap the Doc component into the table structure with thead and tfoot according to the size of your header and footer(table is wrapped inside a div).
<div style="width: 100%;">
<table style="table-layout: fixed; width: 100%;"> // Add this css to make main table fixed, child tables will still scroll
<thead class="page-break-before">
<tr>
<td>
<div style="height: 80px;"></div> // space for the respective header
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<div> Your Data Goes Here........</div>
</td>
</tr>
</tbody>
<tfoot class="show-in-print page-break-after">
<tr>
<td>
<div style="height: 130px;"></div> // space for the respective footer
</td>
</tr>
</tfoot>
</table>
</div>
Sample Header and footer
<div class="page-break-before">
<div>A long header content...</div>
</div>
<div class=" page-break-after">
<p> A long footer content...</p>
</div>

Related

Creating a two column page

Right, so I want to create a page that has two columns and one header at the top of each one. I am using Vue.js to create this webpage. Ideally what I would want is to have the two headers at the top of the page with a gap in between and then the text and stuff below. I've tried to add the column break to make the right hand column start with the header, but it always starts a few lines below that and will not align with the other header.
As said I am using Vue.js, but I don't think that has anything to do with what I'm trying to achieve here. Please be lenient I'm very new to all this. I also tried adding the column feature in the CSS but that didn't work either.
The styles will then be stored in a different file.
I would appreciate any help on this matter. Thank you.
.commsHeaderleft {
width: 40%;
text-align: center;
}
.commsColumns {
align: left;
width: 100%;
text-align: justify;
column-count: 2;
column-gap: 40px;
}
.commsHeaderright {
width: 100%;
text-align: center;
}
<template>
<div>
<div class="commsHeaderleft">
<h1>Join us on Teamspeak!</h1>
</div>
<div class="commsColumns">
<p>--snip--</p>
<p>--snip--</p>
<p>Once installed set up a Bookmark to Air Combat Group using the following connection details and join in.</p>
<table id="tsDetails">
<tr>
<td>Address:</td>
<td>snip</td>
</tr>
<tr>
<td>Password:</td>
<td>No Password Set</td>
</tr>
</table>
<p>snip</p>
<p>snip</p>
<div class="commsHeaderright">
<h1>Check us out on Discord!</h1>
</div>
<p>snip</p>
<p>Discord is a free installation available <u>here</u></p>
<p>snip</p>
<table id="dsDetails">
<tr>
<td>Invite link:</td>
<td>https://discord.gg/snip</td>
</tr>
</table>
<br>
<p>snip</p>
<iframe src="https://discordapp.com/widget?id=261587898996883458&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe>
</div>
</div>
</template>
You can use flexbox to do that : https://css-tricks.com/snippets/css/a-guide-to-flexbox/
<div class="page">
<div class="header">
<div class="header__item">header 1</div>
<div class="header__item">header 2</div>
</div>
<div class="content">
content
</div>
</div>
.header{
display: flex;
margin: 0 0 30px 0;
}
.header__item{
flex: 1
}

css footer not occupy the space and content not showed completely

I am trying to make a footer by css and want the footer to be the bottom of page, however, some content are stretch to inside the footer,
the following are my footer css
#footer {
position: fixed;
bottom: 0;
width: 100%;
}
<div id="footer" style="background-color:#0099CC">
<center>
<table style="width:100%">
<tr>
<td valign="top">Copyright © 2016, Chaatz</td>
<td align="right" style="white-space:pre">Terms and Conditions
Privacy Notice</td>
</tr>
</table>
</center>
<br>
<br>
</div>
You can use the height of the footer element as a padding-bottom of the content and negate the same value in margin-top of the footer element.
<div class="wrapper">
page content
</div>
<div class="footer">
footer content
</div>
.wrapper{
height:100%;
padding-bottom:150px;
}
.footer{
height:150px;
margin-top:-150px;
}

How to center container with unknown width and floated elements inside on fluid page

I know there are lots of ways to center content with an unknown width on a fluid width page in HTML/CSS but I can't get them to work in this case for some reason and need help.
Firstly, let me state that I need a solution that works in common browsers and in IE6 (don't ask why).
Here's an example of markup and the problem. In this example I want the yellow boxes centered inside the blue box.
example on jsfiddle.net
<div style="background:blue;margin:0 auto;width:100%;">
<table style="margin:0 auto;">
<tr>
<td>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<td>
</tr>
</table>
</div>
I tried this method using a table but I also tried the -50% +50% method. I am happy to use any method that works on all common browsers and IE6.
Can someone help me fix it.
Please do not lecture me on IE6 or incorrect use of the TABLE tag.
Try this,
<tr>
<td>
<div style="width: 379px;">
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
<div style="background:yellow;float:left;padding:50px;">Test</div>
</div>
</td>
</tr>
what I understood from your requirement that you want to make your div to center ? then please have a look on the below code
<style type="text/css">
.yourclass
{
background:yellow;
float:left;
padding:50px;
}
.blueback
{
background:blue;
}
.mytable
{
width: auto;
margin-left: auto;
margin-right: auto;
}
div.clear
{
clear:both;
}
</style>
<div class="blueback">
<table class="mytable">
<tr>
<td>
<div class="yourclass">Test</div>
<div class="yourclass">Test</div>
<div class="yourclass">Test</div>
<div class="clear"></div>
<div class="yourclass">Test</div>
<div class="yourclass">Test</div>
<div class="yourclass">Test</div>
</td>
</tr>
</table>
Hope it helps...
After lots of research I can find no solution to this that works in all browsers and doesn't require IE6 hacks.
The best solution is display:inline-block and IE6/7 and various other hacks (eg. FF2).
The final solution taken from here is as follows:
<style>
li {
width: 200px;
min-height: 250px;
border: 1px solid #000;
display: -moz-inline-stack;
display: inline-block;
vertical-align: top;
margin: 5px;
zoom: 1;
*display: inline;
_height: 250px;
}
</style>
<li>
<div>
<h4>This is awesome</h4>
<img src="http://farm4.static.flickr.com/3623/3279671785_d1f2e665b6_s.jpg"
alt="lobster" width="75" height="75"/>
</div>
</li>

HTML Stretch header and footer to long content without JS

I'm having a small issue here, I've made a jsfiddle for you guys to play with it: http://jsfiddle.net/darkguy2008/NQUz8/
The problem I have is that when there is unavoidable long content, the header and footer don't stretch to it, but to the maximum browser window.
I need to find a way to make it stretch, I've had an idea of having the header and footer be part of the content div instead, but if the content is shorter than the browser window they wouldn't stretch to 100% width of the browser window and that's what I don't want.
Also, the title/subtitle of the page can be longer than the content so that wouldn't help either :/
I would love to change the design, but it's for a report website, I can't put it with a margin: 0 auto; because the idea isn't to center the website or to make the reports a fixed width (because they can't, either).
The idea is also to avoid JS. I know I can fix the widths using JQuery, but the project can also be used by external clients so we can't enforce them to use JS. Weird I know but I've seen cases where the stupid sysadmins block JS and we can't do much about it, except to make it work.
I can use HTML5 and CSS3, so if there's a way to do it with those two technologies it would be great :)
Any ideas are welcome!
HTML:
<header>
<div class="wrap">
<table border="0">
<tr>
<td rowspan="2">
<img src="http://dummyimage.com/230x100/000/fff&text=LOGO" align="left" style="border-width:0px;" />
</td>
<td>
<h1>title 1 lololol</h1>
</td>
</tr>
<tr>
<td>
<h2>subtitle omgomgomgomgomg</h2>
</td>
</tr>
</table>
</div>
<div id="menu">menu goes here omg</div>
</header>
<div>contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent</div>
<footer>
<div class="wrap">
<p>Footer goes here o.o"</p>
</div>
</footer>
CSS:
/*********************/
/** RESET */
/*********************/
*
{
padding: 0;
margin: 0;
/*border: 0;*/
font-family: Arial;
}
/*********************/
/** Main CSS */
/*********************/
body
{
font-family: Arial;
font-size: 10pt;
}
.wrap
{
position: relative;
margin: 0 0;
width: 640px;
}
header, footer
{
background: #0f6;
float:left;
min-width:100%;
}
#menu
{
min-width: 100%;
border-top: 2px solid red;
border-bottom: 2px solid red;
}
th, td { padding: 0; }
table { border-collapse:collapse; border-spacing: 0; }
Basically you have to include the content and the footer inside your "header" element so your content will make it grow.
HTML
<div>
<header>
<div class="wrap">
<table border="0">
<tr>
<td rowspan="2">
<img src="http://dummyimage.com/230x100/000/fff&text=LOGO" align="left" style="border-width:0px;" />
</td>
<td>
<h1>title 1 lololol</h1>
</td>
</tr>
<tr>
<td>
<h2>subtitle omgomgomgomgomg</h2>
</td>
</tr>
</table>
</div>
<div id="menu">menu goes here omg</div>
<div class="content">contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent</div>
<footer>
<div class="wrap">
<p>Footer goes here o.o"</p>
</div>
</footer>
</header>
</div>
Modifications in CSS:
.content
{
background: #FFFFFF;
}
Here is a working fiddle:
Fiddle
As in the last post, use the word-wrap here and set your width to whatever you want it to. I set it for you at 100% but it only goes to whatever the largest width you have. http://jsfiddle.net/NQUz8/2/
<div style="word-wrap:break-word; width="100%;">content here</div>
I would use some type of css class or id if you can. I just used style here to show you how it works.

Two container next to each other at full width (each container can be hidden)

I searched a lot, but now want to ask because I found no answer:
If have two div elements that should be located next to each other with full width (each exactly 50% of the full width). It could be that the first or the second div is hidden (style="display=none"). In this case the other div should be displayed in full width.
My solution is this:
<table style="width: 100%;">
<tr>
<td style="padding: 0px;">
<div id="div1">
...
</div>
</td>
<td style="padding: 0px;">
<div id="div2">
...
</div>
</td>
</tr>
</table>
That works almost perfect, BUT when both divs are displayed the first one seems to be 55% and the second one 45% of the width.
If course I can set the width of the div when hiding the other to 100%, but I want to avoid doing that.
Does anyone have a solution to make them both 50% when both are displayed.
A JQuery approach with no tables
You can achieve this with JQuery (or plain javascript) which I am assuming you are using to show/hide the elements anyway.
$("#ButtonOne").click(function () {
$(".one").toggle();
if($(".one").is(":visible")){
$(".two").css("width", "50%");
}
else{
$(".two").css("width", "100%");
}
});
$("#ButtonTwo").click(function () {
$(".two").toggle();
if($(".two").is(":visible")){
$(".one").css("width", "50%");
}
else{
$(".one").css("width", "100%");
}
});
The above JQuery assumes two buttons for toggling the visibility of the elements.
Here is an example
With the example, it should be noted that using 50% width with inline-block requires zero whitespace in between the elements. Hence the </div><div... requirement.
You will need some vertical-align:top; aswell to ensure the DIV elements stay in line.
Incase the link ever breaks, here is the accompanying HTML...
<div class="main">
<div class="one">this is one</div><div class="two">this is two</div>
</div>
<input type="button" id="ButtonOne" value="Toggle one" />
<input type="button" id="ButtonTwo" value="Toggle two" />
...and CSS...
body{
margin:0;
padding:0;
}
div{
margin:0;
padding:0;
}
.one {
background-color:red;
height:100px;
width:50%;
display:inline-block;
}
.two {
background-color:blue;
height:100px;
width:50%;
display:inline-block;
}
Can you place both divs in the same table cell?
<table style="width: 100%;">
<tr>
<td>
<div id="div1">
...
</div>
<div id="div2">
...
</div>
</td>
</tr>
</table>
You could simply toggle a class....
table { width: 100%; padding:0; }
td { padding:0; margin:0; }
td > div { width: 50%; display: block; float: left; height: 50px; cursor: pointer; }
#div1 {background: #a00;}
#div2 {background: #00a;}
.wide {width: 100%;}
.hide { display: none;}
and the jquery...
$('div').click(function () {
$(this).toggleClass('wide');
$('div').not(this).toggleClass('hide');
});
DEMO HERE
Would work for multiple divs easily: demo 2
Use table-layout:fixed:
EDIT:
You have to set the display:none on the td, not on the div.
<table style="width: 100%; table-layout:fixed">
<tbody>
<tr>
<td style="padding: 0px; width:50%">
<div id="div1" style="border: 1px solid black">
This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text
</div>
</td>
<td style="padding: 0px; width:50%; display: none;">
<div id="div2" style="border: 1px solid black">
This isn't as long as the other text.
</div>
</td>
</tr>
</tbody>
</table>
I've tested it on Chrome, Firefox and IE10
ok guys,
thanks for your help. now i found what i was searching for:
<table style="width: 100%;">
<tr>
<td id="td1" style="padding: 0px; min-width:50%;">
<div>
...
</div>
</td>
<td id="td2" style="padding: 0px; min-width:50%;">
<div>
...
</div>
</td>
</tr>
</table>
both td tags are next to each other and both take exactly 50%. when hiding td1 or td2, the other td goes into full width automatically.
best regards...
You can achieve this by setting width in the td itself, and when you want to hide any one div just add "display:none;" in the specified td instead of the div, then the remaining div will have 100% width.
<table style="width: 100%;">
<tr>
<td style="padding: 0px; width:50%;">
<div id="div1" >
hii
</div>
</td>
<td style="padding: 0px;width:50%;">
<div id="div2" style="">
byyee
</div>
</td>
</tr>
</table>