search

Home  >  Q&A  >  body text

css3 - 怎样让网页里的内容随着浏览器窗口改变而自动居中

就是让网页里的内容随着浏览器窗口改变时跟着自动居中呢……怎样实现?有好点的常用的思路吗

伊谢尔伦伊谢尔伦2767 days ago557

reply all(6)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 11:35:55

    Use js to get the window size and element position, and then set the content position according to the obtained values. Pure css can also be used, but it feels not flexible enough

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 11:35:55

    Recommend your own blog: http://blog.csdn.net/zp1996323/article/details/50936259, the effect achieved is vertical centering and horizontal centering

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:35:55

    margin-right:auto;
    margin-left:auto

    reply
    0
  • 黄舟

    黄舟2017-04-17 11:35:55

    position: absolute;
    left:0;
    right:0;
    top:0;
    bottom:0;
    margin:auto;
    width:XXpx;
    height:XXpx;

    reply
    0
  • 黄舟

    黄舟2017-04-17 11:35:55

    position: absolute;
    left:0;
    right:0;
    top:0;
    bottom:0;
    margin:auto;
    width:XXpx;
    height:XXpx;
    
    这个方法不兼容IE6/7,移动端考虑可以使用。

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:35:55

    1. CSS implementation method (width and height are known in advance): The layer that needs to be centered uses absolute positioning, and combines left, top, margin-left and margin-top to achieve centering.
    2. js implementation, I won’t say much about this.

    reply
    0
  • Cancelreply