简体   繁体   English

Bootstrap图像响应式握把

[英]Bootstrap image responsive grip

The requirement is that I need to implement some form of the Bootstrap grid system . 要求是我需要实现某种形式的Bootstrap网格系统 I decided to have responsive images with text description on each image on my page, so when viewing from the desktop the images are side by side and when viewed from mobile the images are stacked including the text. 我决定在页面上的每个图像上都有响应图像和文本描述,因此当从桌面查看时,图像是并排的,当从移动设备查看时,图像堆叠在一起,包括文本。

Here is my HTML code 这是我的HTML代码

<div class="container borderColor" >
          <h1 id="example-id-name" class="centered-text sansSerif-text">STOR/E</h1>
           <p class="centered-text"> Every great story begins on a blank page </p> 


           <div class="row">
    <div class="col-sm-6 img-responsive ">
        <img src="images/book1" alt="book one">
    </div>
    <div class="col-sm-6 img-responsive ">
        <img src="images/book2" alt="book two">
    </div>
</div>

My CSS

    .img-responsive{
        display: block;
        max-width: 100%;
        height: auto;
    }

Use inline-block 使用内联块

  .img-responsive{ display: inline-block; max-width: 100%; height: auto; } 
 <div class="container borderColor" > <h1 id="example-id-name" class="centered-text sansSerif-text">STOR/E</h1> <p class="centered-text"> Every great story begins on a blank page </p> <div class="row"> <div class="col-sm-6 img-responsive "> <img src="https://i.imgur.com/kTa0GuA.png" alt="book one"> </div> <div class="col-sm-6 img-responsive "> <img src="https://i.imgur.com/kTa0GuA.png" alt="book two"> </div> </div> 

You can either use floats or inline-block/block. 您可以使用浮点数或内联块/块。 I plugged in some arbitrary numbers but it's like this: 我插入了一些任意数字,但它是这样的:

.img-responsive{
    display: block;
    max-width: 100%;
    width: 25%;       /* or whatever you want*/
    height: auto;
    float: left;
}

@media only screen and (max-width: 600px) {   /* or whatever your mobile width is */
    .img-responsive {
        float: none;
        width: 100%;
    }
}

I am giving this code by expecting that you are using bootsrap If you are using bootstrap then no need of any css Just use this code instead 我通过期待你正在使用bootsrap给我这个代码如果你使用bootstrap然后不需要任何css只需使用这个代码代替

STOR/E Every great story begins on a blank page STOR / E每个伟大的故事都从一个空白页面开始

  <div class="row"> <div class="col-sm-6 col-xs-12 "> <img class=" img-responsive" src="images/book1" alt="book one"> </div> <div class="col-sm-6 col-xs-12"> <img class=" img-responsive" src="images/book2" alt="book two"> </div> 

No matter how large your image is, it will display responsive 无论您的图像有多大,它都会显示出响应

figured it out thanks for the guidance 想通了,谢谢你的指导

<div class="container borderColor" >
              <h1 id="example-id-name" class="centered-text sansSerif-text">STOR/E</h1>
               <p class="centered-text"> Every great story begins on a blank page </p> 

            <div class="row">
                <div class="col-md-4 left "><p class="centered-text">Paper</p><img class="img-fluid img-thumbnail" src="images/book2"></div>
                <div class="col-md-4 center"><p class="centered-text">Pens</p><img class="img-fluid img-thumbnail" src="images/pens"></div>
                <div class="col-md-4 right"><p class="centered-text">Covers</p><img class="img-fluid img-thumbnail" src="images/cover1"></div>
            </div>    
        </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM