问答详情
源自:13-8 我就在那不动了-层模型之固定定位

层模型--固定定位

固定定位后怎么才能让div1 居中呢?

不固定定位就可以居中,该怎么破啊大神们


提问者:echojson 2016-04-17 16:36

个回答

  • 哈哈我在大笑
    2016-04-17 16:55:23
    已采纳

    div{

    height:60px;

        width:150px;

        line-height:60px;

    background:#ccc;

        position:fixed;

        margin:auto;

        left:0;

        right:0;

        top:0;

        bottom:0;

    }


    只左右居中,去掉top bottom =0

    只上下居中,去掉left righr = 0


    注意:要限制height和width  否则也不会居中


  • 土豆_2
    2016-04-17 16:43:14

    div1{text-align:center;}