代码之家  ›  专栏  ›  技术社区  ›  MK-DK

使列宽小于768px

  •  1
  • MK-DK  · 技术社区  · 7 年前

    我正在使用引导程序3.3.7。

    我无法理解为什么我的图片在以下视窗范围内没有全宽拍摄: > 630px < 768px . 图片宽度为 400px 哪个比较合适 > 768px .

    我可以把这些照片照得合适 <768 PX 如果我把宽度设为800像素。但这张照片越来越吸引人了 >768px .

    是否可以保持现在的宽度,但使图片变为全宽 <768px ?

    演示版本可以是 seen here

      /* Card and Button */
    
        body {
            background-color: #f5f5f5;
        }
        div { 
            background-color: #fff;
        }
        .index-content a:hover {
          color: black;
          text-decoration: none;
        }
    
        .index-content {
          /*margin-bottom: 20px;*/
          /*padding: 50px 0px;*/
        }
    
        .index-content .row {
          margin-top: 20px;
        }
    
        .index-content a {
          color: black;
        }
    
        .index-content .card {
          background-color: #FFFFFF;
          padding: 0;
          -webkit-border-radius: 4px;
          -moz-border-radius: 4px;
          border-radius: 4px;
          box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
        }
    
        .index-content .card:hover {
          box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
          color: black;
        }
    
        .index-content .card img {
          width: 100%;
          border-top-left-radius: 4px;
          border-top-right-radius: 4px;
          height: 350px;
        }
    
        .index-content .card h4 {
          margin: 20px;
        }
    
        .index-content .card p {
          margin: 20px;
          opacity: 0.65;
        }
    
        .index-content .blue-button {
          width: 100px;
          -webkit-transition: background-color 1s, color 1s;
          /* For Safari 3.1 to 6.0 */
          transition: background-color 0.5s, color 0.5s;
          min-height: 20px;
          background-color: #002E5B;
          color: #ffffff;
          border-radius: 4px;
          text-align: center;
          font-weight: lighter;
          margin: 0px 20px 15px 20px;
          padding: 5px 0px;
          display: inline-block;
        }
    
        .index-content .blue-button:hover {
          background-color: #dadada;
          color: #002E5B;
        }
    
        /* GRID ELEMENTS MEDIA QUERIES */
    
        
        @media (min-width: 768px) {
            .card {
                position: relative;
            }
            .card-content {
                position: absolute;
                bottom: 0;
                width: 100%;
                background: rgba(0, 0, 0, 0.5);
            }
            .card-content h4,
            .card-content p {
                color: white;
                width: 100%;
                float: left;
                margin: 0 0 5px;
            }
            .card-content a {
                float: right;
            }
            .index-content .card h4,
            .index-content .card p {
                padding: 15px 20px;
                margin: 0;
            }
            .index-content .card p {
                padding: 0 20px 15px;
                margin: 0;
            }
        }
    
        .margin_bottom{
            margin-bottom:10px;
        }
        .row [class*="col-"]{ 
            padding-right: 5px;
            padding-left: 5px; 
        }
        .row { 
            margin-left: -5px; 
            margin-right: -5px; 
        }
        
        .card-img-bottom {
      color: #fff;
      height: 20rem;
      background: url(images/img1.jpg) center no-repeat;
      background-size: cover;
    }
    <div class="container">
      <div class="row">
        <div class="col-sm-4 margin_bottom">
            <img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
        </div>
        <div class="col-sm-4">
            <div class="row">
                <div class="col-xs-6 col-sm-12 margin_bottom">
                    <img src="http://placehold.it/400x245" alt="5" class="img-responsive"></img>
                </div>
                <div class="col-xs-6 col-sm-12 margin_bottom">
                    <img src="http://placehold.it/400x250" alt="5" class="img-responsive"></img>
                </div>
            </div>
        </div>
        <div class="col-sm-4 margin_bottom">
            <img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
        </div>
      </div>
    </div>
    3 回复  |  直到 7 年前
        1
  •  0
  •   djolf    7 年前

    由于您使用的是最小宽度:768px媒体查询,因此您可以简单地添加此css规则,使其在768px以下工作:

    .img-responsive {width:100%;}
    

    如果您不愿意覆盖引导程序的默认类,您可以创建自己的类并将其应用于每个映像。

        2
  •  1
  •   Nandita Sharma    7 年前

    添加此CSS

    @media (max-width: 768px) {
      img {
          width: 100%;
        }
    }
    

    /* Card and Button */
    
    body {
      background-color: #f5f5f5;
    }
    
    div {
      background-color: #fff;
    }
    
    .index-content a:hover {
      color: black;
      text-decoration: none;
    }
    
    .index-content {
      /*margin-bottom: 20px;*/
      /*padding: 50px 0px;*/
    }
    
    .index-content .row {
      margin-top: 20px;
    }
    
    .index-content a {
      color: black;
    }
    
    .index-content .card {
      background-color: #FFFFFF;
      padding: 0;
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      border-radius: 4px;
      box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    }
    
    .index-content .card:hover {
      box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
      color: black;
    }
    
    .index-content .card img {
      width: 100%;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
      height: 350px;
    }
    
    .index-content .card h4 {
      margin: 20px;
    }
    
    .index-content .card p {
      margin: 20px;
      opacity: 0.65;
    }
    
    .index-content .blue-button {
      width: 100px;
      -webkit-transition: background-color 1s, color 1s;
      /* For Safari 3.1 to 6.0 */
      transition: background-color 0.5s, color 0.5s;
      min-height: 20px;
      background-color: #002E5B;
      color: #ffffff;
      border-radius: 4px;
      text-align: center;
      font-weight: lighter;
      margin: 0px 20px 15px 20px;
      padding: 5px 0px;
      display: inline-block;
    }
    
    .index-content .blue-button:hover {
      background-color: #dadada;
      color: #002E5B;
    }
    
    
    /* GRID ELEMENTS MEDIA QUERIES */
    
    @media (min-width: 768px) {
      .card {
        position: relative;
      }
      .card-content {
        position: absolute;
        bottom: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.5);
      }
      .card-content h4,
      .card-content p {
        color: white;
        width: 100%;
        float: left;
        margin: 0 0 5px;
      }
      .card-content a {
        float: right;
      }
      .index-content .card h4,
      .index-content .card p {
        padding: 15px 20px;
        margin: 0;
      }
      .index-content .card p {
        padding: 0 20px 15px;
        margin: 0;
      }
    }
    
    @media (max-width: 768px) {
      img {
        width: 100%;
      }
    }
    
    .margin_bottom {
      margin-bottom: 10px;
    }
    
    .row [class*="col-"] {
      padding-right: 5px;
      padding-left: 5px;
    }
    
    .row {
      margin-left: -5px;
      margin-right: -5px;
    }
    
    .card-img-bottom {
      color: #fff;
      height: 20rem;
      background: url(images/img1.jpg) center no-repeat;
      background-size: cover;
    }
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <div class="container">
      <div class="row">
        <div class="col-sm-4 margin_bottom">
          <img src="http://placehold.it/400x510" alt="5" class="img-responsive" />
        </div>
        <div class="col-sm-4">
          <div class="row">
            <div class="col-xs-6 col-sm-12 margin_bottom">
              <img src="http://placehold.it/400x245" alt="5" class="img-responsive" />
            </div>
            <div class="col-xs-6 col-sm-12 margin_bottom">
              <img src="http://placehold.it/400x250" alt="5" class="img-responsive" />
            </div>
          </div>
        </div>
        <div class="col-sm-4 margin_bottom">
          <img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img>
        </div>
      </div>
    </div>
        3
  •  1
  •   Gopal Garva    7 年前
    <div class="container"> <div class="row"> <div class="col-sm-4 margin_bottom"> <img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img> </div> <div class="col-sm-4"> <div class="row"> <div class="col-xs-6 col-md-12 col-sm-12 margin_bottom"> <img src="http://placehold.it/400x245" alt="5" class="img-responsive"></img> </div> <div class="col-xs-6 col-md-12 col-sm-12 margin_bottom"> <img src="http://placehold.it/400x250" alt="5" class="img-responsive"></img> </div> </div> </div> <div class="col-sm-4 margin_bottom"> <img src="http://placehold.it/400x510" alt="5" class="img-responsive"></img> </div> </div> </div>
    

    用这个替换你的HTML,你只需要在你的代码中添加col-md-12。 或者您可以使用媒体查询来实现这一点。干得好:

    @media (max-width:767px){.col-sm-12 img{width:100%;}}