Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactjs specific component printing with css

import React, { Component } from "react";

import { Button } from "semantic-ui-react";

class JobReleaseForm extends Component {

render() {
return (

  <div id="no-print">

    <Button onClick={() => window.print()}>PRINT</Button>

    <p>Click above button opens print preview with these words on page</p>

  </div>
);
}
}
    export default JobReleaseForm;

Hello there, I am trying to figure it out how to only print out the contents of this component not the surrounding ones. I found this.

 @media print{
*{display:none;}
#no-print{display:block;}
}

but I cant figure where or how to put it with reactjs. Especially the @media part. Any help is appreciated Thanks

like image 408
benonymus Avatar asked Oct 21 '25 04:10

benonymus


1 Answers

While I was waiting I came with this solution

@media print {
  body * {
    visibility: hidden;
  }

  #section-to-print, #section-to-print * {
    visibility: visible;
  }

  #section-to-print {
    position: absolute;
    left: 0;
    top: 0;
  }
}

And it is working just fine for now

Thank you all

like image 189
benonymus Avatar answered Oct 23 '25 21:10

benonymus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!