浮动图像不与换行符保持一致?

时间:2019-04-09 21:17:54

标签: html css flexbox

我有一个要漂浮在flexbox容器旁边的图像,但没有这样做。

如何将图像与段落放在同一行?

.info {
  display: flex;
  flex-direction: column;
  padding: 1vw 3vw 1vw 0vw;
  display: inline-block;
}

.sketch {
  float: right;
  max-width: 50%;
  height: auto;
  margin: 2vw 0vw;
  display: inline-block;
}
<div class="first">
  <div class="info">
    <p id="time">Lorem ipsum dolor sit amet</p>
    <p id="guest">consectetur adipiscing elit</p>
    <p id="first-paragraph">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
      in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </p>
  </div>
  <img class="sketch" src="../assets/photo.jpg">
</div>

1 个答案:

答案 0 :(得分:2)

只需将<img>标记放在<p>标记上即可。

.info {
  display: flex;
  flex-direction: column;
  padding: 1vw 3vw 1vw 0vw;
  display: inline-block;
  
}

.sketch {
  float: right;
  max-width: 50%;
  height: auto;
  margin: 2vw 0vw;
  display: inline-block;
}
<div class="first">
  <div class="info">
    <p id="time">Lorem ipsum dolor sit amet</p>
    <p id="guest">consectetur adipiscing elit</p>
    <img class="sketch" src="https://via.placeholder.com/150">
    <p id="first-paragraph">
      Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
 

    </p>
  </div>
  
</div>