• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

React设置样式style

武飞扬头像
困知勉行1985
帮助2

1.设置行内样式:

1.基本设置:

使用{},传入一个对象{padding: '2px 0 5px 20px',overflowY: 'auto'}

如下所示:

<div style={{padding: '2px 0 5px 20px',overflowY: 'auto'}}

2.设置百分比(相对数据)

<div style={{width: 'calc(100% - 35px)',height: 'calc(100% - 15px)'}}>

3.通过函数设置:

例如,自己写一个计算window高度的函数:

  1.  
    //参数 adjustValue的作用是在window.innerHeight的基础上,减去多少高度,可以是负值,0,正值
  2.  
    function getWinHeight(adjustValue) {
  3.  
    let winHeight;
  4.  
    if (window.innerHeight) {
  5.  
    winHeight = window.innerHeight;
  6.  
    } else if ((document.body) && (document.body.clientHeight)) {
  7.  
    winHeight = document.body.clientHeight;
  8.  
    }
  9.  
    return winHeight-adjustValue;
  10.  
    }

然后在样式中使用:

  1.  
    <div style={{width: 'calc(100% - 35px)',height: getWinHeight(200)}}>
  2.  
    <div id="jsoneditor" className="jsoneditor-react-container" />
  3.  
    </div>

2.杂七杂八:

1.table占满整行:

设置table标签的style 为 style={{width: 'calc(100% - 10px)'}}

  1.  
    <table style={{width: 'calc(100% - 10px)'}}>
  2.  
    <tr>
  3.  
    <td style={{width:'50px'}}>
  4.  
    <div style={{paddingTop:"10px",marginLeft:'10px'}}>
  5.  
    <Button
  6.  
    id="returnButtonId"
  7.  
    text=""
  8.  
    icon={"ic_arrow_back"}
  9.  
    onClick={doBack}
  10.  
    />
  11.  
    </div>
  12.  
    </td>
  13.  
    <td>
  14.  
    <div style={{paddingTop:'10px'}}>Edit Parameter Files</div>
  15.  
    </td>
  16.  
    <td>
  17.  
    <div style={{float:'right', margin:'0 10px 0 10px', paddingTop:'10px'}}>
  18.  
    <Button
  19.  
    id="`uploadButtonId`"
  20.  
    text="UPLOAD"
  21.  
    icon={"ic_arrow_upward"}
  22.  
    onClick={onUploadClicked}
  23.  
    />
  24.  
    </div>
  25.  
    </td>
  26.  
    </tr>
  27.  
    </table>
学新通

2.父 <div>设置高度不起作用:

如果父<div>设置高度不管用,那么必须将子<div>的高度也设置一下,可以跟父<div>的高度保持一致,.

入下图所示:父子<div>的高度都被设置为  getWinHeight(180)

  1.  
    <div style={{height: getWinHeight(180), border:'2px'}}>
  2.  
    <SplitScreen
  3.  
    id="parameterfiles-panel"
  4.  
    left={
  5.  
    <div style={{height: getWinHeight(180)}}>
  6.  
    ..........
  7.  
    </div>
  8.  
    }
  9.  
    right={
  10.  
    <div style={{ whiteSpace: "nowrap"}}>
  11.  
    <div style={{padding: '2px 0 5px 20px',overflowY: 'auto', width: 'calc(100% - 35px)',height: getWinHeight(180)}}>
  12.  
    <div id="jsoneditor" className="jsoneditor-react-container" />
  13.  
    </div>
  14.  
    </div>
  15.  
    }
  16.  
    />
  17.  
    </div>
学新通

暂时写这么多,以后想到别的,再写。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgagjie
系列文章
更多 icon
同类精品
更多 icon
继续加载