加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 系统 > 正文

css让容器水平垂直居中的7种方式

发布时间:2020-03-15 20:30:52 所属栏目:系统 来源:站长网
导读:这篇文章主要为大家详细介绍了css让容器水平垂直居中的7种方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    <div class="center"></div>  

</div>  

  

CSS Code复制内容到剪贴板

/* css */ .wrap { backgroundyellowwidth200pxheight200pxdisplay: flex; align-items: centerjustify-contentcenter;   

} .center { backgroundgreenwidth100pxheight100px;   

}   

  

或者display:flex;margin:auto;

XML/HTML Code复制内容到剪贴板

<!-- html -->  

<div class="wrap">  

    <div class="center"></div>  

</div>  

  

CSS Code复制内容到剪贴板

/* css */ .wrap { backgroundyellowwidth200pxheight200pxdisplay: flex;   

} .center { backgroundgreenwidth100pxheight100pxmarginauto;   

}   

  

如果是PC端,要考虑兼容性的话。方法六是不错滴,也就是纯position。

XML/HTML Code复制内容到剪贴板

<!-- html -->  

<div class="wrap">  

    <div class="center"></div>  

</div>  

  

CSS Code复制内容到剪贴板

/* css */ .wrap { backgroundyellowwidth200pxheight200pxpositionrelative;   

/**方法一**/ .center { backgroundgreenpositionabsolutewidth100pxheight100pxleft50pxtop50px;     

     

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读