How to extend Twitter Bootstrap image carousel for dynamically sized, centered images

前端 未结 3 1540
春和景丽
春和景丽 2021-02-06 04:05

I\'m trying to extend the default Bootstrap image carousel to support dynamically sized images (500x400 max), centered both horizontally and vertically. Additionally, I\'d like

相关标签:
3条回答
  • 2021-02-06 04:37

    try to use this snippet

    .carousel-inner > .item > img {
        min-width: 100%;
    }
    
    0 讨论(0)
  • 2021-02-06 04:39

    Use the CSS background property directly on the div containing the carousel item:

    In the *.html:

    <div class="item" style="background-image: url('[path-to-image].png')">
        <!-- omit the <img> tag -->
        <!-- the rest of the stuff that was in the <div> goes here -->
    </div>
    

    In the *.css:

    .carousel .item {
        background-position: center center;
        background-repeat: no-repeat;
        background-size: cover;
    }
    

    However, this seems to break the carousel navigation arrows.

    0 讨论(0)
  • 2021-02-06 04:51

    You can center horizontally with these rules:

    .carousel-inner { text-align: center; }

    .carousel .item > img { display: inline-block; }

    For vertical aligning you should check out this: http://www.student.oulu.fi/~laurirai/www/css/middle/

    And for keeping the image aspect ratio on resizing you just have to change only the width or only the height of the image not both at a time and it will resize with its original ratio.

    0 讨论(0)
提交回复
热议问题