eeeeeeve
V2EX  ›  CSS

absolute position 布局中,可否不通过 JS 做到让子元素在竖直方向上居中呢?

  •  
  •   eeeeeeve · Jun 24, 2015 · 4660 views
    This topic created in 4159 days ago, the information mentioned may be changed or developed.
    可以用css解决这个问题么,如何解决?
    lifang
    lifang
    Jun 24, 2015
    1
    position:absolute;
    top:50%;
    left:50%;
    margin-top: -子元素一半高度;
    margin-left: -子元素一半宽度;


    这样是水平垂直方向都居中了
    eeeeeeve
    eeeeeeve
    OP
    Jun 24, 2015
    2
    @lifang top:50%没有考虑子元素尺寸啊, 在css中是否可以把子元素的中线和页面中部重合呢?
    top 50% 子元素上部和页面中部重合,不是子元素中部和页面中部重合啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   948 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 832ms · UTC 19:50 · PVG 03:50 · LAX 11:50 · JFK 14:50
    ♥ Do have faith in what you're doing.