juanzirosalind

图片的居中方法

1.水平居中、垂直的方法:

(1)图片的水平居中:a.在其父级设置text-align:center;b.在图片上设置margin: 0 auto;display: block;

图片的水平垂直居中:a.使用displaytabletable-cell;

html:

<div class="center-aligned">

  <div class="center-core">

    <img src="page_1_5.png" alt="">

  </div>

</div>

css:

.center-aligned {

display: table;

background: hsl(120, 100%, 97%);

width: 500px;

height:500px;

}

.center-core {

display: table-cell;

text-align: center;

vertical-align: middle;

}

B.绝对定位position:absolute,left:50%,top:50%,平移transform:translate(-50%, -50%);

C.在父级使用:display: flex;justify-content: center;align-items: center;,但是会有兼容性问题,chrome,火狐支持,IE10部分支持2012,需要-ms-前缀

分类:

技术点:

相关文章:

  • 2022-01-25
  • 2022-01-31
  • 2021-05-26
  • 2021-08-06
  • 2021-09-21
  • 2021-06-13
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-05-01
  • 2021-07-28
  • 2021-11-21
  • 2021-06-06
  • 2021-07-06
  • 2021-06-29
相关资源
相似解决方案