HTML Stretch header and footer to long content without JS - html

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.

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;
}

css pdf page - header overlapping with content

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>

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>

Center text to page not cell

I have a sticky footer bar thanks to the folks at cssstickyfooter which holds a disclaimer. I wanted to put a facebook like button on the right hand side... so I created a table with the below code for the footer.
#footer {
position: relative;
margin-top: -60px;
height: 60px;
clear:both;
background-color: #000;
text-align: center;
color: #999;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
and the html as
<div id="footer">
<table width="100%">
<tr>
<td width="85%">
<p>© 2011 somecompany<br />
Image © 2011 by somebig company</p>
</td>
<td width="15%">
<p>like goes here</p>
</td>
</tr>
</table>
</div>
This (obviously) aligns the the text, but it aligns it to the cell that it is in. Is there anyway to align the disclaimer text to the center of the whole page and keep the like button to the right?
I have thought about just putting the like button in its own table and have that floating there... but I'm not sure.
Theres a jsfiddle example over at http://jsfiddle.net/Gnznn/
Thanks!
Marked as homework so I can get an explaination
I have a feeling there is a cleaner* way to do this, but this at least works and does not use tables for layout. Note, I put the styles in an attribute so you could see what I was doing easier, but you should put that in your declarations in relevant classes.
<div id="footer">
<div style="width: 15%; height: 1px; float: left;"></div>
<div style="width: 70%; float: left;">
<p>© 2011 somecompany<br />Image © 2011 by somebig company</p>
</div>
<div style="width: 15%; float: right;">
<p>like goes here</p>
</div>
</div>
http://jsfiddle.net/Gnznn/3/
* In other words, using position: relative or position: absolute with right: 0 and z-index: 5000 (or something).