I want to add a footer in all the pdf pages generated from HTML when printed, but only for the first page, I want to add a section below the common footer. I have to do it using only HTML and CSS.
<head>
<style>
.footerLeft {
position: running(footerLeft);
}
#page {
margin-bottom: 40%;
margin-top: 5%;
#bottom-left {
content: element(footerLeft);
}
}
</style>
</head>
<body>
<div class="footerLeft">
...content
</div>
</body>
I want to add another div below the "footerLeft" div class only for the first page. I am using this thymeleaf for the final compilation, would want to know if there is any property that can help me achieve this apart from plain HTML & CSS. Can somebody please help me with this problem?
Related
Not sure if this is possible or not, my requirement is something like this - I have a web page having three div which are wrapped inside another main div having display:flex so that all the three div can appear adjacent to each other. Now the issue is that in the middle div I am extracting some data from my database which itself contains DIVs. the divs may not be properly closed i:e few might not be closed with /div. So when the data appears on the middle div, the third div sometimes goes out of the flex box causing issue in the layout. Is there any possible way to avoid this ? Hope I am able to explain my issue.
As a rule, we never inject user generated content into a page without properly sanitising it to help prevent security vulnerabilities such as XSS. Please research HTML sanitisation and make sure you're processing this user generated content safely.
With that being said, browsers are quite forgiving of improperly formatted markup and will try their best to render what you give them. So to prevent this user generated content messing with your page you're going to want to isolate these documents from the rest of your page.
Instead of dropping this user generated html directly in the page you could provide it as a srcdoc to an iframe like so:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>foo</title>
<style type="text/css" media="screen">
.container {
display: flex;
}
.one, .two, .three {
height 200px;
}
.one {
background-color: red;
}
.two {
background-color: green;
}
.three {
background-color: blue;
}
.inline {
border: none;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div class="container">
<div class="one">
<iframe class="inline" srcdoc="<div><h1>my parent was not properly closed</h1>"></iframe>
</div>
<div class="two">
<iframe class="inline" srcdoc="<div><div><h2>nor mine</h2>"></iframe>
</div>
<div class="three">
<iframe class="inline" srcdoc="<div><div><div><h3>neither was mine</h3>"></iframe>
</div>
</div>
</body>
</html>
SO I'm trying to recreate this webpage and am working on the style of the div that I will be using 7 times to span the nav bar and am having trouble getting the referenced image to load in.
I will now post my code. I am using style in the page for quick access but will use an external style sheet when I am done.
<!DOCTYPE html>
<html>
<header class="header" id="header" align="middle">
<img src="https://s21.postimg.org/luvg05cjb/header.jpg">
</header>
<style>
.Home {
position: absolute;
background-image: url("https://postimg.org/image/vg652px3f/");
background-size: 99px 30px;
left: 290px;
top: 234px;
text-align: center;
line-height: 30px;
width: 99px;
height: 30px;
color: black;
}
</style>
<body>
<div class="Home">Home</div>
<h1></h1>
<p></p>
</body>
</html>
There are several things wrong with your code:
There is no head tag in the document.
You can't simply put <header> tags outside of <body> element. (http://www.w3schools.com/tags/tag_header.asp)
Style tags should be placed inside <head> or <body> tag.
This is not an image URL >> https://postimg.org/image/vg652px3f/
Firstly you are using a website address in the background image style, not an actual image.
The image that you may be referring to is actually at the link:
https://s9.postimg.org/mxwoydqkv/menubg.jpg
Edit: If your goal is to show a website inside your website, you should be using an iframe.
<iframe src="https://postimg.org/image/vg652px3f/"></iframe>
I am trying to make a online form, which has header(with the logo of the company) and footer( with three different addresses). And in the body there are so many things. I need to flow the header logo in every page of the form but I need to fix my footer only on the first page not in every page.
For the header logo i am using
#page { #top {content: flow(page_header); }} .
but when i use the same thing for the footer it is not working. Can anybody help me about this?
Note: I am using docraptor for converting the html into pdf.
Developer at DocRaptor here. You can do this using some simple CSS. Here is a full demonstrative example:
<!DOCTYPE html>
<html>
<head>
<style>
h1 { flow: static(page_header); }
h2 { flow: static(first_page_footer); }
#page {
#top { content: flow(page_header); }
}
#page:first {
#bottom { content: flow(first_page_footer); }
}
hr { page-break-after: always; }
</style>
</head>
<body>
<h1>Header Content</h1>
<h2>Footer Content</h2>
<p>Page 1 content.</p>
<hr />
<p>Page 2 content.</p>
</body>
</html>
Hope that helps! Email DR Support if you run into any different questions or want to say hi. :)
I need to make a report in HTML that is supposed to be A4 size exactly. It needs headers and footers. Surely this can be done with css yeah?
does anyone have any examples or sample code for this?
I googled and the code snippets I got all talk about media queries and they don't work..
so basically it is for print Purposes, the html generated will be converted to a PDF document.
I am using MVC4 and found a tool that will convert a view to a PDF. A view is just pure HTML. So I thought why not style the HTML to represent the output report, then PDF it.
So I need the ability to have a header, and a footer (bottom of the page) and then content in the middle of both of them
I tried using the following code, but it doesn't seem to work..
<html>
<head>
<style type="text/css" media="all">
#page {
size: A4 portrait; /* can use also 'landscape' for orientation */
margin: 1.0in;
border: thin solid black;
padding: 1em;
#bottom-center {
content: element(footer);
}
#top-center {
content: element(header);
}
}
#page-header {
display: block;
position: running(header);
}
#page-footer {
display: block;
position: running(footer);
}
.page-number:before {
content: counter(page);
}
.page-count:before {
content: counter(pages);
}
</style>
</head>
<body>
<div id="page-header">
<p>Header text</p>
</div>
<div id="page-footer">
<p>Footer text</p>
<p>Page <span class="page-number"/> of <span class="page-count"/></p>
</div>
<div id="page-content">
<p>Page 1.</p>
<p style="page-break-after:always;"/>
<p>Page 2.</p>
</div>
</body>
</html>
CSS can be used to set width/height to a real-world size; for example in your print.css file:
div.A4 {
width: 21 cm;
height: 29.7 cm;
margin: 0;
}
However, HTML/CSS really isn't meant for this purpose; media queries really are the best way to handle this. I'd really recommend you put a little more time trying to get them working; it's worth the time if you plan on using this website more than once.
Why A4 size? For printing purposes?
If for printing purposes you wont even have to worry about it. Use CSS for that purpose.
If your html element is displaying as a block element (the default) and you don't specify any width or height then the html document will resize to the printer settings document when you attempt to print.
If you ever need to adjust any css settings for printing then use css media queries
Ignore this answer if it's not related to printing, but provide more details in your post so we can provide the correct solution.
Hope it makes sense
Leo
I would like to know if there is a way to use a particular css page as styling for a tag.
For example, instead of
<div class="header" style="position: absolute; text-align:left; right: auto; margin: 0 auto 20px; z-index: 1; width: 60%; height: auto; left:9%">
Is there a way to specify style.css for the div tag?
For example,
This style.css must ONLY apply to the div tag above.
Also, is it possible for all tags contained within that div tag to follow the same specified css page?
Put this in the header of your page
<head>
<link rel="stylesheet" href="/styles.css" type="text/css">
</head>
If you want to specify style for a page, include that CSS when you render the page.
If you want to have multiple ways of rendering a particular tag, differentiate the tags.
I'm not aware of conditional logic you can apply to the CSS directly.
HTML:
(include this in the head)
<link href='style.css' rel='stylesheet' type='text/css'/>
CSS: (in the style.css file)
div.header{
//your style here
}
or without the class:
div{
//your style here
}
but without the class it will get all div tags so I recommend the first code
You can create the CSS page you want and then create the styling you want inside
something like this
div > table {
padding: 5px;
}
That would make the div have a padding of five as well as it's child the table a padding of 5