Absolute center a fluid div

前端 未结 3 1671
独厮守ぢ
独厮守ぢ 2021-01-23 07:45

Good day.

I know that if you want to absolute center a div, you do this:

blahblah
3条回答
  •  星月不相逢
    2021-01-23 08:15

    As the width and height are fluid, you need to go with javascript or jQuery. Just add the below code in head tag. (The below example is in javascript)

    
    

    and your css would be something like this:

    #parent{
       max-width: 500px;
       max-height: 500px;
       background-color:green;
       position:absolute;
       top: 50%;
       left: 50%;
      /* width: 10%;
       height: 10%; */
    }
    

    To test, give width: 10%; and height: 10%

    Working Fiddle

提交回复
热议问题