How to keep an image centered and responsive?

前端 未结 7 1346
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 18:08

I have an image, centered both, horizontally and vertically

#logo01{
    position:absolute;
    top:50%;
    left:50%;
    margin-top:-146px;  // half of hei         


        
7条回答
  •  Happy的楠姐
    2021-01-02 18:34

    Below is my suggestion. It works for any

    and ...

    and the css code is:

    .responsive{
       max-width:100%;
       max-height:100%;
     }
    
    .center{
      position: absolute;
      top: 50%;
      left: 50%; 
      transform: translate(-50%, -50%);
    }
    
    .parent{
      position: relative;
    }
    

    just find and test a live demo here: https://jsfiddle.net/veuodbk7/2/

提交回复
热议问题