Concealing Elements During Web Page Printing
Printing a web page is a common task, but it can be frustrating to have unwanted elements appear in the printout. One such element that often poses a nuisance is the print button itself. If you're looking to remove the print button from your printed pages, here's how you can achieve this:
CSS Media Queries
Media queries in Cascading Style Sheets (CSS) allow you to define styles specifically for printouts. To hide elements when printing, you can use the @media print rule:
@media print { .no-print, .no-print * { display: none !important; } }
Applying the Class
Once you have the CSS rule in place, you need to add a class to the element you want to conceal. You can either assign the no-print class directly:
<button class="no-print">Print</button>
Or append it to an existing class:
<button class="btn btn-primary no-print">Print</button>
Example
Consider the following example:
<p>Good Evening</p> <button>
@media print { #print-button { display: none !important; } }
When the page is printed, the "Print" button will be hidden, leaving only the text "Good Evening" on the printout.
Note:
The !important declaration ensures that the display: none style is applied even if other styles attempt to override it.
The above is the detailed content of How Can I Hide Elements Like Print Buttons When Printing a Web Page?. For more information, please follow other related articles on the PHP Chinese website!