Bootstrap Responsive Images Scaling

后端 未结 3 1229
独厮守ぢ
独厮守ぢ 2021-02-14 22:17

Using Twitter Bootstrap I realize that by default it scales images responsively. This is great, but isn\'t always perfect.

Say for example I have a 50

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-14 22:48

    I have seen how other sites actually don't scale the image much, but rather use the parent div to sort of mask the image

    If you examine the CSS on the page you mention, you will see that rather than using imline images, they are typically defining divs with background images, and using CSS like

    #some-div {
    background-size: 100%;
    background-size: cover;
    background-position: center center;
    vertical-align: top;
    background-image: url(/.../image.jpg);
    }  
    

    Here's an example of how you can get completely different results with scaling of inline image vs background-image.

    http://www.bootply.com/67094

    The key to the second method is to use background-size:cover and manipulate the size of the div (and hence the size of the background-image).

    http://css-tricks.com/perfect-full-page-background-image/ has good info about variations and options with background-cover.

提交回复
热议问题