html5图片标记无法与Bootstrap响应

时间:2018-08-01 19:36:13

标签: html css twitter-bootstrap

我正在尝试使用html5 <picture>标签设置不同的图片。我将2张图片设置在引导网格内,因此图片会一直响应,直到图片发生变化的断点768px

当我最小化浏览器的屏幕尺寸时,我可以看到图片没有响应。这个怎么可能?引导代码应该正确吗?

A demo can be seen here

该HTML代码在代码段中看起来不太好。因此,我将其发布到:

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12 col-sm-12 margin_bottom">
            <picture>
                <source media="(min-width: 650px)" srcset="http://vouzalis.dk/1024.jpg">
                <source media="(min-width: 380px)" srcset="http://vouzalis.dk/380.jpg">
                <img src="http://vouzalis.dk/1024.jpg" alt=“test” style="width:auto;">
            </picture>
            <div class="inner-wrapper bottom-left">
                <h3>Here is headline 1</h3>
            </div>
        </div>
    </div>
</div>

body {
      background-color: #f5f5f5;
    }
    /* Set width between grid elements */
    .small-padding.top {
       padding-top:10px;
    }

    .small-padding.bottom {
        padding-bottom:10px;
    } 
    .small-padding.left {
        padding-left:5px;
    }

    .small-padding.right {
        padding-right:5px;
    }
    .margin_bottom {
      margin-bottom: 10px;
    }
    .row [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
    .row {
      margin-left: -5px;
      margin-right: -5px;
    }
    .img-responsive { 
        height: 100%;
    }
    /* Position of buttons/text in a single grid element */
    .inner-wrapper {
      text-align: center;
      background: none;
    }
    .centered {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .bottom-right {
        position: absolute;
        bottom: 8px;
        right: 16px;
    }

    .bottom-left {
        position: absolute;

        bottom: 8px;
        left: 16px;
    }
    /* Color on text */
    .dark-font {
      color: #333;
    }
    .light-font {
      color: #fff;
    }
   
    /* Set full width on columns */
    @media (max-width: 768px) {
      .img-responsive { /*EDIT*/
        width: 100%;
        height: auto;
        }
      .btn-success {
        width: fit-content;
      }
      /* Here you go */
      .height-m {
        height: 350px;
      }

    }

    @media (max-width: 991px) {
      h3 {
        font-size: 1.2em;

      }
    }
<div class="container-fluid">
	<div class="row">
        <div class="col-xs-12 col-sm-12 margin_bottom">
          	<picture>
                <source media="(min-width: 650px)" srcset="http://vouzalis.dk/1024.jpg">
                <source media="(min-width: 380px)" srcset="http://vouzalis.dk/380.jpg">
                <img src="http://vouzalis.dk/1024.jpg" alt=“test” style="width:auto;">
            </picture>
            <div class="inner-wrapper bottom-left">
                <h3>Here is headline 1</h3>
            </div>
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:2)

您使用的boostrap模板确实是正确的,并且确实提供了某种响应能力,但是image没有指定的width。因此,浏览器无法缩放它。

相对于其父级设置width应该可以解决它,例如

width: 100%

答案 1 :(得分:0)

将图像宽度设置为100%而不是auto可以使它响应。