Responsive images in tables (bootstrap 3)

前端 未结 5 1493
失恋的感觉
失恋的感觉 2020-12-15 07:05

I\'m using the Bootstrap 3 Framework and have some troubles with the \"img-responsive\" class in Firefox. I have a 4 column-Table with 15/50/10/25% layout. In the first colu

相关标签:
5条回答
  • 2020-12-15 07:41

    The answer from Bass

    .img-responsive {
       width:100%;
    }
    

    does work, but it also scales up other images.

    What I have done instead is create another class as

    .img-responsive-2 { 
       width: 100%; 
    }
    

    and put it together with the original .img-responsive so that I have the flexibility to use it only for images in tables.

    <img src="someimage.jpg" class="img-responsive img-responsive-2" />
    
    0 讨论(0)
  • 2020-12-15 07:46

    Try this code

    $(window).load(function() {
        $('img.img-responsive').each(function(){
            // Remember image size
            var imgWidth = $(this).width();
            // hide image 
            $(this).hide();
            // if container width < image width, we add width:100% for image 
            if ( $(this).parent().width() < imgWidth ) { $(this).css('width', '100%'); }
            // show image
            $(this).show();
        });
    });
    
    0 讨论(0)
  • 2020-12-15 07:47

    add .img-responsive{width:100%;} to your css, see also: Why do Firefox and Opera ignore max-width inside of display: table-cell?

    0 讨论(0)
  • 2020-12-15 07:51

    I also had this problem, the solution for me was "table-layout fixed"

    .table-container {
        display: table;
        table-layout: fixed;
        width: 100%;
        height: 100%;
    }
    .table-cell-container {
        text-align: left;
        display: table-cell;
        vertical-align: middle;
        &.center{
            text-align: center;
        }
        img{
            display: inline-block;
            width: auto;
            max-width: 100%;
            height: auto;
            max-height: 100%;
    
        }
    }
    
    <div class="table-container">
    <div class="table-cell-container center">
             <img src="myimage.jpg" width="100" height="100" alt="myimage" />
    </div>
    </div>
    
    0 讨论(0)
  • 2020-12-15 07:54

    My custom css:

    table .img-responsive {
        width: 100%;
    }
    
    0 讨论(0)
提交回复
热议问题