pjk_ok
pjk_ok

Reputation: 947

Floating Text Around an Image issue

I have some text I wish to wrap around an image - I understand I need to float the image to the left to force the text to wrap around it. Whatever I do doesn't seem to work?

I've set up a codepen here: https://codepen.io/emilychews/pen/GmdZOb

Code is below for quick reference.

* {
  padding: 0;
  margin: 0;
}

.outer {
  width: 50%;
  height: 50vh;
  background: blue;
}

.inner {
  display: block;
  width: 25%;
  height: 25vh;
  background: red;
  float: left;
  margin-right: 10px;
}

p {
  color: white;
}
<div class="outer">
  <p>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 </p>
  <div class="inner">IMAGE</div>
</div>

Upvotes: 1

Views: 41

Answers (1)

j08691
j08691

Reputation: 207901

You need to put your image before the text so that the text can float up along side it.

* {
  padding: 0;
  margin: 0;
}

.outer {
  width: 50%;
  height: 50vh;
  background: blue;
}

.inner {
  display: block;
  width: 25%;
  height: 25vh;
  background: red;
  float: left;
  margin-right: 10px;
}

p {
  color: white;
}
<div class="outer">
  <div class="inner">IMAGE</div>
  <p>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 </p>
</div>

Upvotes: 5

Related Questions