首页 > 解决方案 > Make image scale next to a div inside a div

问题描述

I am creating a webpage where I need to have a two boxes of text right next to each other as long as the other div has content, then the main text will take the width of the whole space.

However, as the text will scale fine, any image will not and will to the the bottom of the small div, leaving a huge empty space between main text and the image.

Is there a simple way to force the images to scale to the side of the inner div or do I need another solution for this?

Thank you in advance! :)

.container {
 width: 600px;
}

.long-text {
  overflow: hidden;
  width: 100%;
  background: white;
}

.long-text p {}

.long-text img {
  width: auto;
  max-height: 400px;
}

.right-column {
  width: 200px;
  float: right;
  background: green;
  padding: 5px 0 0 18px;
}
<div class="container">
  <div class="long-text">
    <div class="right-column">
      <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
      </p>
      <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
      </p>
    </div>
    <p>
      It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    </p>
    <img src="https://placeimg.com/640/480/any">
    <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable
    </p>
    <p>
      It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </div>
</div>

JS filddle: https://jsfiddle.net/marginaalivirhe/d8yLko24/8/

标签: htmlcssimage

解决方案


您还可以为每个分辨率进行布局。

@mediacss 中https://www.w3schools.com/css/css3_mediaqueries.asp


推荐阅读