I have a "Print" button in my web page (php html) and I don't want it to print along with my data. Can I do it with CSS? Is there another way?
            Asked
            
        
        
            Active
            
        
            Viewed 4,422 times
        
    2
            
            
        - 
                    Instead of hiding that button open a new window with javascript with the content you want to print and call the javascript function to print in that window and close it. – vedarthk Mar 08 '13 at 10:10
- 
                    2He's asking for the CSS way, not the JS way. – Jamie Hutber Mar 08 '13 at 10:10
- 
                    @JamieHutber I am not sure whether CSS way will work on all browsers. That is why I suggested that option. – vedarthk Mar 08 '13 at 10:11
- 
                    fair enough. css won't work with all browsers. – Jamie Hutber Mar 08 '13 at 10:12
- 
                    I need to pass variables with php so I can't use window.open() – CMartins Mar 08 '13 at 10:14
- 
                    @CarlosMartins That is not an issue, you can send data via GET in URLs. – vedarthk Mar 08 '13 at 10:15
3 Answers
3
            Yes you can with CSS, although support will only be with browsers that support CSS3.
But its simple:
 @media print {
    …
 }
 
    
    
        Jamie Hutber
        
- 26,790
- 46
- 179
- 291
1
            
            
        assign an id(buttonId) to the button eg: id="buttonId"
and then in css:
#buttonId
{
    display:none;
}
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
just use the above css file for the same.
 
    
    
        Kumar Saurabh Sinha
        
- 880
- 8
- 23
- 
                    
- 
                    I think it wont hide the other buttons as id is used and only one element will have that id in the page – Kumar Saurabh Sinha Mar 08 '13 at 10:17
1
            
            
        Just create multiple style sheets
<style type="text/css" media="all"> @import "nucss2.css";</style>
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
And look at the
media="print"
 
    
    
        Jordy van Eijk
        
- 2,718
- 2
- 19
- 37
 
    