居中

作者: 白小菜的路 | 来源:发表于2017-12-13 16:26 被阅读0次

1. 大包小 只是水平居中 margin:auto dispaly:table

<style>
  #ex2_container { width:200px; height:300px; background-color:yellow; }
  #ex2_content {  height:100px; width:100px; margin:0px auto; background-color:gray; color:white; display:table; }
</style>
<div id="ex2_container"><div id="ex2_content">Hello World</div></div>
image.png

2 translate(-50%,-50%)

<style>
  #ex3_container { width:200px; height:200px; background-color:yellow; position:relative; }
  #ex3_content {height:100px; width:120px; left:50%; top:50%; transform:translate(-50%,-50%); -webkit-transform:translate(-50%,-50%); background-color:gray; color:white; position:absolute; }
</style>
<div id="ex3_container"><div id="ex3_content">Hello World</div></div>
image.png

3. 绝对定位居中

<style>
#ex2_container {
  width: 300px;
  height:200px;
  background-color:yellow;
  position: relative;
/*   text-align:center; */
}
#ex2_content {
  width:100px;
  height:100px;
  background-color:grey;
/* width: 50%;
  height: 50%; */
  overflow: auto;
  margin: auto;
  position: absolute;
  top: 0; left: 0; bottom: 0;   right: 0;
}
</style>
<div id="ex2_container">
  <div id="ex2_content">Hello World</div>
</div>
image.png

4. 用于mask 布局

<style>
#ex2_container,#is-Fixed {
  position:fixed;
  background-color:yellow;
  top:0;
  right:0;
  left:0;
  bottom:0;
}
#ex2_container #is-Fixed {
  width: 100px;
  height: 100px;
 */ width: 60%; 
  height: 60%;
  min-width: 400px;
  max-width: 500px;*/
  overflow: auto;
  margin: auto;
  z-index: 999;
  background-color:grey;
}
</style>
<div id="ex2_container">
  <div id="is-Fixed">Hello World</div>
</div>
image.png

参考文献

CSS 居中大全

相关文章

  • 多行文本固定高度垂直居中

    话不多说直接上代码! html: 居中居中居中居中居中居中 css: #Mian{ width:50...

  • css 居中

    居中有水平居中和垂直居中。 水平居中+垂直居中 flex法 position法 就是计算呗~ 参考 CSS各种居中...

  • css居中方式总结(亲测有效)

    水平居中(行内元素水平居中、块级元素水平居中) 垂直居中 水平垂直居中 行内元素水平居中 text-align: ...

  • 居中布局

    水平居中 垂直居中 垂直水平居中 已知元素的宽高的居中布局 定位居中布局 盒模型居中布局 图片的垂直水平居中(利用...

  • css 居中效果

    上下居中: 左右居中: 整页居中:

  • Ant Design使用 Table组件实现内容居中的效果

    未居中效果 未居中效果截图 居中效果 居中效果截图

  • HTML 水平居中和垂直居中

    水平居中 文字居中 图片居中 绝对定位元素 居中 相对定位 负边距居中 垂直居中 文字设置line-height ...

  • 常用的居中方法

    本文将介绍的居中方法有 ,水平居中,垂直居中和水平垂直居中。 一水平居中 二水平垂直居中

  • CSS居中布局方案

    水平居中 垂直居中 水平垂直居中

  • 居中对齐

    行内元素居中[#hang]垂直居中[#hc]水平居中[#hs] 块级元素居中[#kuai]垂直居中[#kc]水平居...

网友评论

      本文标题:居中

      本文链接:https://www.haomeiwen.com/subject/axtzixtx.html