如何在图像中创建响应div?

时间:2017-06-08 04:56:54

标签: html css responsive-design

我正在尝试创建一个响应式容器,其中包含一个图像和一个div,图像上有一些文本。像这样:

.tileimage {
  position: absolute;
  width: 100%;
  height:auto;
  color: white;
}

.tileseven {
  position: absolute;
  width: 100%;
  height:auto;
}
<div className="container">
  <img className="col-lg-12 tileimage" src="./tile.jpg" alt=""/>
  <div className="col-lg-12 tileseven">
      <img className="" src="./logo.png" alt=""/>
      <p>this is some text</p>
  </div>
</div>

如何使logo.png响应?当我调整浏览器大小时,图像会调整大小而不是徽标?另外,如何将div.tileseven叠加在底部的图像上?

3 个答案:

答案 0 :(得分:1)

看看这个!!!试试这个。 //

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
<style>
  div.gallery {
      border: 1px solid #ccc;
  }

  div.gallery:hover {
      border: 1px solid #777;
  }

  div.gallery img {
      width: 100%;
      height: auto;
  }

  div.desc {
      padding: 15px;
      text-align: center;
  }

  * {
      box-sizing: border-box;
  }

  .responsive {
      padding: 0 6px;
      float: left;
      width: 24.99999%;
  }

  @media only screen and (max-width: 700px){
      .responsive {
          width: 49.99999%;
          margin: 6px 0;
      }
  }

  @media only screen and (max-width: 500px){
      .responsive {
          width: 100%;
      }
  }

  .clearfix:after {
      content: "";
      display: table;
      clear: both;
  }
</style>
</head>
<body>

  <h2>Responsive Image Gallery</h2>
  <h4>Resize the browser window to see the effect.</h4>

  <div class="responsive">
    <div class="gallery">
      <a target="_blank" href="img_fjords.jpg">
        <img src="img_fjords.jpg" alt="Trolltunga Norway" width="300" height="200">
      </a>
      <div class="desc">Add a description of the image here</div>
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <a target="_blank" href="img_forest.jpg">
        <img src="img_forest.jpg" alt="Forest" width="600" height="400">
      </a>
      <div class="desc">Add a description of the image here</div>
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <a target="_blank" href="img_lights.jpg">
        <img src="img_lights.jpg" alt="Northern Lights" width="600" height="400">
      </a>
      <div class="desc">Add a description of the image here</div>
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <a target="_blank" href="img_mountains.jpg">
        <img src="img_mountains.jpg" alt="Mountains" width="600" height="400">
      </a>
      <div class="desc">Add a description of the image here</div>
    </div>
  </div>

  <div class="clearfix"></div>

  <div style="padding:6px;">
    <p>This example use media queries to re-arrange the images on different screen sizes: for screens larger than 700px wide, it will show four images side by side, for screens smaller than 700px, it will show two images side by side. For screens smaller than 500px, the images will stack vertically (100%).</p>
  </div>
</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

要调整徽标的大小,您需要引用图像而不仅仅是包含div

.tileseven img {
     height: auto;
     width: 100%;
 }

至于保持最佳状态,你总是可以在那里抛出一个z-index。

答案 2 :(得分:0)

您可以通过将徽标的宽度定义为100%来使徽标响应。以下是css:

.tileseven img {
   width: 100%;
} 

使用CSS中的left,top和z-index进行div.tileseven叠加播放。