-->
SEO

آخر الأخبار

SEO
جاري التحميل ...

How to Create Custom CSS Template for Printing


Along with the development of web technologies and web programming languages, web designing becoming more complex and the websites more flexible and user friendly. With the invention of CSS technology, web designing and programming becoming more easier than ever.

By using cascading style sheet (CSS) and its properties, you can give custom design to your website for different medias like screen, print, tv and for different screen sizes. The CSS @media property allows you to do such task.

Today I am going to describe "How to create custom CSS template for printing".

Designing Custom CSS Template for Printing


If you wanted to allow your website visitors to print the content of your website, you can design custom template for printing using CSS. You can define which part or your website will be printed or not and can add page setting for printing.

Designing Custom CSS Template for Printing

Here is a sample CSS code for website template.


body{
background:#00aaff;
font-color:#00000;
font-size:16px;
}

h1, h2, h3 {

/* CSS codes for h1, h2, h3 */

}

#wrapper{
width:80%;
margin: 0 auto;
background:#fff;
padding:20px;
}

#content{
width:54%;
float:left;
margin-right:3%;
}

#header{
width:100%;
margin-top:2%;
}

#sidebar-left{
width:20%;
float:left:
margin-right:3%;
}

#sidebar-right{
width:20%;
float:left;
}

#footer{
width:100%;
}


While printing you can hide default header, menu and sidebar using CSS codes. Here is a sample CSS code for printing webpage.


body{
background:#00aaff;
font-color:#00000;
font-size:16px;
}

h1, h2, h3 {

/* CSS codes for h1, h2, h3 */

}

#wrapper{
width:80%;
margin: 0 auto;
background:#fff;
padding:20px;
}

#header{
display:none;
}


#content{
width:100%;
clear:both;
margin-right:3%;
}

#sidebar-left{
display:none;
}

#sidebar-right{
display:none;
}

#footer{
display:none;
}


Place the above CSS code inside media queries for printing as below.

@media only print and (orientation:portrait) { 
    
     /* Add CSS code here for printing on portrait mode */
 }

@media only print and (orientation:landscape) { 
    
     /* Add CSS code here for printing on landscape mode */
 }



Adding Printing function and icon



Add the following HTML code where you want to place print icon.

<a href="javascript:window.print()"> Print this page </a>

Using this code the print link looks like as below                                     Print this page


<a href="javascript:window.print()"> <img src="print.jpg"></a>

Print
Using this code the print icon looks like as below


<form><input type="button" value="Print This" onclick="window.print()"></form>

Using this code the print button looks like as below                                                            



Related Posts:



    welcome to the forex

    التعليقات



    جميع الحقوق محفوظة

    Publications

    2016