SlideShare ist ein Scribd-Unternehmen logo
1 von 58
CSS GOING TO PRINT
CSS can be used to specify  how a document is presented   in different media .
We can determine which CSS rules are given to specific devices using the  media attribute :  <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=&quot; sc reen&quot;  /> <link rel=&quot;stylesheet” href=&quot; a. css&quot; type=&quot; te xt/css&quot;  media=&quot; print &quot;  /> <link rel=&quot;stylesheet” href=&quot; a. css&quot; type=&quot; te xt/css&quot;  media=” handheld &quot;  />
So, what are possible media types?
There are  ten media types  defined in CSS 2.1
suitable for all devices for speech synthesizers for Braille tactile feedback devices for paged Braille printers for handheld devices for print material for projected presentations for color computer screens for teletypes and terminals for television type devices all aural braille embossed handheld print projection screen tty tv
Can you  specify more than one at the same time?
Yes, you can use  multiple media types  within the one attribute: <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=&quot; sc reen, print&quot;  />
Are there different  methods we  can use?
There are  five methods  that can be used to specify media  for style sheets.
However, some methods are complex, and other can cause issues in some browsers, so we will only look at the  two safest methods .
Method 1:  <link> within HTML
You can use a  <link> element  in the head of your HTML document to specify the target media of an external style sheet. <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=&quot;print&quot;  />
Method 2: @media within CSS
You can specify the target medium within a CSS file using  @media @media  screen   { body { color: blue; } }
What is this @media?
At-rules  start with an ' @ ' character followed immediately  by an identifier (such as “media” or “import”).
In CSS2.1 there are  four possible at-rules :  - @charset - @import - @media - @page
We are only going to look at @media now, and focus on  how it can be used to deliver CSS to printers .
@media rules can  sit  anywhere inside  your  external CSS style sheet. body { color: red; } @media  screen   { body { color: blue; } }
@media rules include the @media statement, followed by a media type,  followed by a start and end bracket . @media screen  { }
Any standard CSS rule can be  added inside these brackets . @media screen  { p { color: red; } #nav { float: left; } .intro { font-weight: bold; } }
You can specify more than one media type using @media rules. Each media type must be  separated by a comma . @media  screen, print   { p { color: red; } #nav { float: left; } }
How does @media work?
1. Different devices (such as browsers, printers and mobiles) will see the  <link> element in the HTML file . <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=”all&quot;  />
2. These devices will then  look at the CSS file .
3. The CSS file can included one or more @media rules,  each targeting a different device .  @media  screen  { } @media  print  { } @media  handheld  { }
4. Each device will  only read the rules assigned to it , based on the media type.  @media screen { } @media print { } @media handheld { }
If you want to specify more than one media type inside your CSS file, make sure your <link> element uses a  media type of “all” . <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=”screen&quot;  /> <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=”all&quot;  />
Otherwise all the other different types of devices will not look inside the CSS file at all.
Why use @media?
The main advantage of @media is that you only need one CSS file, and it can be used to control  all the different media . @media  screen  { } @media  print  { } @media  handheld  { }
This means there are less hits to the server, and  only one link in your HTML files , which makes maintenance easier. <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=”print&quot;  /> <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot;  media=”all&quot;  />
So, let’s talk about print CSS
Trying to set up print CSS can often be  very frustrating  for designers and developers.
There are a wide variety of  different solutions  to deal with: Different operating systems Different browsers Different printers Different colour options
There are also a range of printing  issues  to deal with: Background images not printing Background colors not printing Printing first page only Broken page layouts
Decision:  Replicate or reduce
The two main  main options  for printing are: Replicate what is on screen Reduce to a print friendly version
Option 1:  Replicating what is on screen
To allow your pages to appear the same in print as on screen, you can  simple adjust the media type .
Add  an additional media type to your @import rule. @media screen,  print  { }
However, you should be aware that  things are never that easy !
Background images and colors  will not print for users as a default. This can make your screen design look odd when printed.
Floats and absolutely  positioned elements can sometimes cut off after the first page (especially in some version of FireFox)
Layouts can sometimes cut off look  squashed  when printed.
Although it sounds more complicated, it is often much easier to  deliver a print friendly version .
Option 2: Create new,  simpler rules for printers only
Linking to print CSS Target: Screen and print <link rel=&quot;stylesheet” href=” master.css &quot; type=&quot;text/css”>
Create two @media rules - one  for screen and one for print . @media screen {  /* screen rules here */  } @media print  { /* print rules here */  }
Any tips for simple print CSS?
Here are  some pointers  for easy print friendly pages.
Tip 1:  Convert colors to black and white where possible. h1, h2, h3, h4, h5, h6  {  color: #000;  }
Tip 2:  Hide sections of the page that  are unnecessary. #navigation, #sidebar, #adbanner, #richfooter {  display: none;  }
Tip 3:  Convert links to default text color and style - if you want! a:link, a:visited { color: #000; text-decoration: none; }
Tip 4:  Avoid floats, absolute positioning and height 100%. #container {  float: none;  }
Tip 5:  Keep it simple! Remember that the goal is to create a page that is easy to print and read.
Russ Weakley Max Design Site:  maxdesign.com.au Twitter:  twitter.com/russmaxdesign Slideshare:  slideshare.net/maxdesign Linkedin:   linkedin.com/in/russweakley

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
vikasgaur31
 
Images and Tables in HTML
Images and Tables in HTMLImages and Tables in HTML
Images and Tables in HTML
Aarti P
 

Was ist angesagt? (20)

HTML/HTML5
HTML/HTML5HTML/HTML5
HTML/HTML5
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
 
Html links
Html linksHtml links
Html links
 
HTML/CSS/java Script/Jquery
HTML/CSS/java Script/JqueryHTML/CSS/java Script/Jquery
HTML/CSS/java Script/Jquery
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
What is CSS?
What is CSS?What is CSS?
What is CSS?
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntax
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
How to learn HTML in 10 Days
How to learn HTML in 10 DaysHow to learn HTML in 10 Days
How to learn HTML in 10 Days
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
Html tables
Html tablesHtml tables
Html tables
 
Nested lists in HTML
Nested lists in HTMLNested lists in HTML
Nested lists in HTML
 
HTML 5 Complete Reference
HTML 5 Complete ReferenceHTML 5 Complete Reference
HTML 5 Complete Reference
 
Html ppt
Html pptHtml ppt
Html ppt
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Images and Tables in HTML
Images and Tables in HTMLImages and Tables in HTML
Images and Tables in HTML
 
Basic Html Notes
Basic Html NotesBasic Html Notes
Basic Html Notes
 

Andere mochten auch

Braille Presentation
Braille Presentation Braille Presentation
Braille Presentation
anagd
 

Andere mochten auch (20)

Generating print output from DITA using CSS
Generating print output from DITA using CSSGenerating print output from DITA using CSS
Generating print output from DITA using CSS
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
How to Create an Array & types in PHP
How to Create an Array & types in PHP How to Create an Array & types in PHP
How to Create an Array & types in PHP
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
BrailleTap
BrailleTapBrailleTap
BrailleTap
 
Braile
BraileBraile
Braile
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
Javascript (parte 1)
Javascript (parte 1)Javascript (parte 1)
Javascript (parte 1)
 
Ecommerce final
Ecommerce finalEcommerce final
Ecommerce final
 
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
 
Html ppt
Html pptHtml ppt
Html ppt
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
Braille Presentation
Braille Presentation Braille Presentation
Braille Presentation
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 

Ähnlich wie Print CSS

Basics Of Css And Some Common Mistakes
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
sanjay2211
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
butest
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
butest
 

Ähnlich wie Print CSS (20)

CSS media types
CSS media typesCSS media types
CSS media types
 
Css
CssCss
Css
 
Css
CssCss
Css
 
CSS
CSSCSS
CSS
 
Cascading Style Sheets - CSS - Tutorial
Cascading Style Sheets - CSS  -  TutorialCascading Style Sheets - CSS  -  Tutorial
Cascading Style Sheets - CSS - Tutorial
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
 
Css intro
Css introCss intro
Css intro
 
Css
CssCss
Css
 
WELCOME-FOLKS--CSS.-AND-HTMLS.pptx
WELCOME-FOLKS--CSS.-AND-HTMLS.pptxWELCOME-FOLKS--CSS.-AND-HTMLS.pptx
WELCOME-FOLKS--CSS.-AND-HTMLS.pptx
 
Lesson 8 Computer Creating your Website.pdf
Lesson 8 Computer Creating your Website.pdfLesson 8 Computer Creating your Website.pdf
Lesson 8 Computer Creating your Website.pdf
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
 
Basics Of Css And Some Common Mistakes
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
 
Css
CssCss
Css
 
HTML & CSS Workshop Notes
HTML & CSS Workshop NotesHTML & CSS Workshop Notes
HTML & CSS Workshop Notes
 
Chapter 3 - CSS.pdf
Chapter 3 - CSS.pdfChapter 3 - CSS.pdf
Chapter 3 - CSS.pdf
 
Team styles
Team stylesTeam styles
Team styles
 

Mehr von Russ Weakley

Mehr von Russ Weakley (20)

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windows
 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptions
 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible names
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?
 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI components
 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?
 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design Systems
 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletes
 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loader
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and glory
 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messages
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and Errors
 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?
 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern Libraries
 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern libraries
 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24
 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-complete
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
 
Creating an Accessible button dropdown
Creating an Accessible button dropdownCreating an Accessible button dropdown
Creating an Accessible button dropdown
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Print CSS

  • 1. CSS GOING TO PRINT
  • 2. CSS can be used to specify how a document is presented in different media .
  • 3. We can determine which CSS rules are given to specific devices using the media attribute : <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=&quot; sc reen&quot; /> <link rel=&quot;stylesheet” href=&quot; a. css&quot; type=&quot; te xt/css&quot; media=&quot; print &quot; /> <link rel=&quot;stylesheet” href=&quot; a. css&quot; type=&quot; te xt/css&quot; media=” handheld &quot; />
  • 4. So, what are possible media types?
  • 5. There are ten media types defined in CSS 2.1
  • 6. suitable for all devices for speech synthesizers for Braille tactile feedback devices for paged Braille printers for handheld devices for print material for projected presentations for color computer screens for teletypes and terminals for television type devices all aural braille embossed handheld print projection screen tty tv
  • 7. Can you specify more than one at the same time?
  • 8. Yes, you can use multiple media types within the one attribute: <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=&quot; sc reen, print&quot; />
  • 9. Are there different methods we can use?
  • 10. There are five methods that can be used to specify media for style sheets.
  • 11. However, some methods are complex, and other can cause issues in some browsers, so we will only look at the two safest methods .
  • 12. Method 1: <link> within HTML
  • 13. You can use a <link> element in the head of your HTML document to specify the target media of an external style sheet. <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=&quot;print&quot; />
  • 14. Method 2: @media within CSS
  • 15. You can specify the target medium within a CSS file using @media @media screen { body { color: blue; } }
  • 16. What is this @media?
  • 17. At-rules start with an ' @ ' character followed immediately by an identifier (such as “media” or “import”).
  • 18. In CSS2.1 there are four possible at-rules : - @charset - @import - @media - @page
  • 19. We are only going to look at @media now, and focus on how it can be used to deliver CSS to printers .
  • 20. @media rules can sit anywhere inside your external CSS style sheet. body { color: red; } @media screen { body { color: blue; } }
  • 21. @media rules include the @media statement, followed by a media type, followed by a start and end bracket . @media screen { }
  • 22. Any standard CSS rule can be added inside these brackets . @media screen { p { color: red; } #nav { float: left; } .intro { font-weight: bold; } }
  • 23. You can specify more than one media type using @media rules. Each media type must be separated by a comma . @media screen, print { p { color: red; } #nav { float: left; } }
  • 25. 1. Different devices (such as browsers, printers and mobiles) will see the <link> element in the HTML file . <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=”all&quot; />
  • 26. 2. These devices will then look at the CSS file .
  • 27. 3. The CSS file can included one or more @media rules, each targeting a different device . @media screen { } @media print { } @media handheld { }
  • 28. 4. Each device will only read the rules assigned to it , based on the media type. @media screen { } @media print { } @media handheld { }
  • 29. If you want to specify more than one media type inside your CSS file, make sure your <link> element uses a media type of “all” . <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=”screen&quot; /> <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=”all&quot; />
  • 30. Otherwise all the other different types of devices will not look inside the CSS file at all.
  • 32. The main advantage of @media is that you only need one CSS file, and it can be used to control all the different media . @media screen { } @media print { } @media handheld { }
  • 33. This means there are less hits to the server, and only one link in your HTML files , which makes maintenance easier. <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=”print&quot; /> <link rel=&quot;stylesheet” href=&quot; a. css” type=&quot; te xt/css&quot; media=”all&quot; />
  • 34. So, let’s talk about print CSS
  • 35. Trying to set up print CSS can often be very frustrating for designers and developers.
  • 36. There are a wide variety of different solutions to deal with: Different operating systems Different browsers Different printers Different colour options
  • 37. There are also a range of printing issues to deal with: Background images not printing Background colors not printing Printing first page only Broken page layouts
  • 38. Decision: Replicate or reduce
  • 39. The two main main options for printing are: Replicate what is on screen Reduce to a print friendly version
  • 40. Option 1: Replicating what is on screen
  • 41. To allow your pages to appear the same in print as on screen, you can simple adjust the media type .
  • 42. Add an additional media type to your @import rule. @media screen, print { }
  • 43. However, you should be aware that things are never that easy !
  • 44. Background images and colors will not print for users as a default. This can make your screen design look odd when printed.
  • 45. Floats and absolutely positioned elements can sometimes cut off after the first page (especially in some version of FireFox)
  • 46. Layouts can sometimes cut off look squashed when printed.
  • 47. Although it sounds more complicated, it is often much easier to deliver a print friendly version .
  • 48. Option 2: Create new, simpler rules for printers only
  • 49. Linking to print CSS Target: Screen and print <link rel=&quot;stylesheet” href=” master.css &quot; type=&quot;text/css”>
  • 50. Create two @media rules - one for screen and one for print . @media screen { /* screen rules here */ } @media print { /* print rules here */ }
  • 51. Any tips for simple print CSS?
  • 52. Here are some pointers for easy print friendly pages.
  • 53. Tip 1: Convert colors to black and white where possible. h1, h2, h3, h4, h5, h6 { color: #000; }
  • 54. Tip 2: Hide sections of the page that are unnecessary. #navigation, #sidebar, #adbanner, #richfooter { display: none; }
  • 55. Tip 3: Convert links to default text color and style - if you want! a:link, a:visited { color: #000; text-decoration: none; }
  • 56. Tip 4: Avoid floats, absolute positioning and height 100%. #container { float: none; }
  • 57. Tip 5: Keep it simple! Remember that the goal is to create a page that is easy to print and read.
  • 58. Russ Weakley Max Design Site: maxdesign.com.au Twitter: twitter.com/russmaxdesign Slideshare: slideshare.net/maxdesign Linkedin: linkedin.com/in/russweakley