React里单页面div自适应浏览器高度占满屏幕

思路:可以用绝对定位方式,让div占满屏幕,css样式如下:

  height: 100%;
width: 100%;
position: absolute;
top: 0px;
bottom: 0px;

例子:

render() {
return (
< body >
< div className= "container" >
< h1 className= "login-title" >Computer Examination </ h1 >
< Form onSubmit= {this. handleSubmit } className= "login-form" >
< FormItem >
< Input prefix= { < Icon type= "user" style= {{ color: 'rgba(0,0,0,.25)' } } /> } placeholder= "管理员账号/职工号/学号" />
</ FormItem >
< FormItem >
< Input prefix= { < Icon type= "lock" style= {{ color: 'rgba(0,0,0,.25)' } } /> } type= "password" placeholder= "密码" />
</ FormItem >
< FormItem >
< Checkbox className= "login-form-checkbox" >记住我 </ Checkbox >
< a className= "login-form-forgot" href= "" >忘记密码 </ a >
< Button type= "primary" htmlType= "submit" className= "login-form-button" >
登陆
</ Button >
</ FormItem >
</ Form >
</ div >
</ body >
);
}

css:

.container {
text-align: center;
background-image: url( ../images/backImg.jpg);
height: 100%;
width: 100%;
background-size: cover;
position: absolute;
top: 0px;
bottom: 0px;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值