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

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

发布时间:2020-03-16 09:23:24 所属栏目:电商 来源:站长网
导读:副标题#e# 方法一:position加margin XML/HTML Code复制内容到剪贴板 divclass=wrap divclass=center/div /div CSS Code复制内容到剪贴板 /**css**/.wrap{width:200px;height:200px;background:yellow;position:relative; }.wrap.center{width:100px;height

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

</div>  

  

CSS Code复制内容到剪贴板

/* css */ .wrap { background: yellow; width: 200px; height: 200px; display: flex; align-items: center; justify-content: center;   

} .center { background: green; width: 100px; height: 100px;   

}   

  

移动端首选

方法五:display:flex;margin:auto

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

<!-- html -->  

<div class="wrap">  

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

</div>  

CSS Code复制内容到剪贴板

/* css */ .wrap { background: yellow; width: 200px; height: 200px; display: flex;    

} .center { background: green; width: 100px; height: 100px; margin: auto;   

}   

  

移动端首选

方法六:纯position

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

<!-- html -->  

<div class="wrap">  

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

</div>  

  

CSS Code复制内容到剪贴板

/* css */ .wrap { background: yellow; width: 200px; height: 200px; position: relative;   

(编辑:核心网)

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

热点阅读