Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

CSS Styling tips for Print

By editor , 12 January, 2017
Question

How to create a css for print on drupal 8 ?

Add CSS for Print

Method 1 : Add a specific styling sheet for Print.

On your theme (THEME.info.yml for D8 and THEME.info for D7), Add css file as [print].
Example
stylesheets[print][] = css/print.css

 

Method 1. In Same style sheet.

Wrap codes for print using @media query.
Example:
@media print
{
  /*Codes For Print*/
}

Tips:

Remove the URL and SRC from print css (Hide address)

  a[href]:after { content: none !important; }
  img[src]:after { content: none !important; }

Add Print Button (Or image)

Example:
<img src="print.png" alt="Print" onclick="window.print()">
<button onclick="window.print()">Print</button>

 

Remove / Replace the html "Select" (selectbox's) dropdown arrow

  select {
    //Remove default arrow
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    &::-ms-expand {
      display: none;
    }
    //Replace with an image
    background-repeat: no-repeat;
    background-image: url("/path_to/selecebox_arrow.png");
    background-position: right;
  }

Tags

  • Drupal 8
  • Code
Basic CSS Styling tips
Add CSS stylesheets to a module (CKEditor)
Test a webpage for Retina display

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer