Dynamically Change width and height of Div using CSS and React
const [size_w,setSize_w]=useState('210mm');
const [size_h,setSize_h]=useState('297mm');
/////////////
const changelayout=()=>{
const temph=size_h==='210mm'?'297mm':'210mm';
const tempw=size_w==='297mm'?'210mm':'297mm'
setSize_h(temph);
setSize_w(tempw);
}
////////////////////
<button className="bg-blue-500 text-white px-4 py-2 mr-2 rounded"
onClick={changelayout}>Change Layout</button>
//////////////
<div ref={contentToPrint} id="printable-content"
style={{ width: size_w, height: size_h }}
className="print-content p-4 bg-white">
</div>
Comments
Post a Comment