Сделать масштаб изображения рядом с div внутри div - PullRequest
0 голосов
/ 19 ноября 2018

Я создаю веб-страницу, на которой мне нужно разместить два поля текста рядом друг с другом, если у другого элемента div есть содержимое, тогда основной текст будет занимать ширину всего пространства.

Однако, поскольку текст будет хорошо масштабироваться, любое изображение не будет и будет располагаться в нижней части небольшого элемента div, оставляя огромное пустое пространство между основным текстом и изображением.

Есть ли простой способ заставить изображения масштабироваться в сторону от внутреннего div или мне нужно другое решение для этого?

Заранее спасибо! :)

.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/

Ответы [ 2 ]

0 голосов
/ 19 ноября 2018

Вы ищете этот результат?

.container {
 width: 600px;
 display:flex
}

.long-text {
  flex-grow:1;
  background: white;
}



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

.right-column {
  width: 200px;
  flex-shrink:0;
  background: green;
  padding: 5px 0 0 18px;
}
<div class="container">
  <div class="long-text">
    
    <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 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>
</div>
0 голосов
/ 19 ноября 2018

Вы также можете сделать макет для каждого разрешения.

С @media в css https://www.w3schools.com/css/css3_mediaqueries.asp

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...