React中設(shè)置樣式style方式
設(shè)置行內(nèi)樣式
1.基本設(shè)置
使用{},傳入一個對象
{padding: '2px 0 5px 20px',overflowY: 'auto'}
如下所示:
<div style={{padding: '2px 0 5px 20px',overflowY: 'auto'}}
2.設(shè)置百分比(相對數(shù)據(jù))
<div style={{width: 'calc(100% - 35px)',height: 'calc(100% - 15px)'}}>
3.通過函數(shù)設(shè)置
例如,自己寫一個計(jì)算window高度的函數(shù):
//參數(shù) adjustValue的作用是在window.innerHeight的基礎(chǔ)上,減去多少高度,可以是負(fù)值,0,正值 function getWinHeight(adjustValue) { let winHeight; if (window.innerHeight) { winHeight = window.innerHeight; } else if ((document.body) && (document.body.clientHeight)) { winHeight = document.body.clientHeight; } return winHeight-adjustValue; }
然后在樣式中使用:
<div style={{width: 'calc(100% - 35px)',height: getWinHeight(200)}}> <div id="jsoneditor" className="jsoneditor-react-container" /> </div>
雜七雜八
1.table占滿整行
設(shè)置table標(biāo)簽的style 為 style={{width: 'calc(100% - 10px)'}}
<table style={{width: 'calc(100% - 10px)'}}> <tr> <td style={{width:'50px'}}> <div style={{paddingTop:"10px",marginLeft:'10px'}}> <Button id="returnButtonId" text="" icon={"ic_arrow_back"} onClick={doBack} /> </div> </td> <td> <div style={{paddingTop:'10px'}}>Edit Parameter Files</div> </td> <td> <div style={{float:'right', margin:'0 10px 0 10px', paddingTop:'10px'}}> <Button id="`uploadButtonId`" text="UPLOAD" icon={"ic_arrow_upward"} onClick={onUploadClicked} /> </div> </td> </tr> </table>
2.父 <div>設(shè)置高度不起作用
如果父<div>設(shè)置高度不管用,那么必須將子<div>的高度也設(shè)置一下,可以跟父<div>的高度保持一致,.
如下所示:父子<div>的高度都被設(shè)置為 getWinHeight(180)
<div style={{height: getWinHeight(180), border:'2px'}}> <SplitScreen id="parameterfiles-panel" left={ <div style={{height: getWinHeight(180)}}> .......... </div> } right={ <div style={{ whiteSpace: "nowrap"}}> <div style={{padding: '2px 0 5px 20px',overflowY: 'auto', width: 'calc(100% - 35px)',height: getWinHeight(180)}}> <div id="jsoneditor" className="jsoneditor-react-container" /> </div> </div> } /> </div>
總結(jié)
暫時寫這么多,以后想到別的,再寫。
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解React如何實(shí)現(xiàn)代碼分割Code Splitting
這篇文章主要為大家介紹了React如何實(shí)現(xiàn)代碼分割Code Splitting示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08TypeScript在React項(xiàng)目中的使用實(shí)踐總結(jié)
這篇文章主要介紹了TypeScript在React項(xiàng)目中的使用總結(jié),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-04-04react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼
本文主要介紹了react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02React+Redux實(shí)現(xiàn)簡單的待辦事項(xiàng)列表ToDoList
這篇文章主要為大家詳細(xì)介紹了React+Redux實(shí)現(xiàn)簡單的待辦事項(xiàng)列表ToDoList,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-09-09React?hook實(shí)現(xiàn)簡單的websocket封裝方式
這篇文章主要介紹了React?hook實(shí)現(xiàn)簡單的websocket封裝方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09