设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 系统 > 正文

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

发布时间:2020-03-16 04:35 所属栏目:52 来源:站长网
导读:divclass=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

    <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;   

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读