CSS: how to vertically and horizontally align an image?

后端 未结 7 913
青春惊慌失措
青春惊慌失措 2020-12-31 12:27

My page has space for an image that can be, say, a maximum 100x100 image. Users can upload any image dimension and the web application will resize it, maintaining aspect rat

相关标签:
7条回答
  • 2020-12-31 13:16
    <div class="blog-thumbnail">                
        <img src="img.jpg" alt="img">
    </div>
    
    .blog-thumbnail {
        height: 200px;
        margin: 0 auto;
        position: relative;
    }
    .blog-thumbnail img {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        top: 0;
        margin: auto;
        max-width: 100%;
        max-height: 100%;
    }
    
    0 讨论(0)
提交回复
热议问题