0

I am trying to get an image to appear in the top right corner of a div, with text first to the left of the image, and then when the image ends, the text should take up the full width of the div.

This is currently what is output:

enter image description here

This is the html:

<div>
<img src="./images/gym.jpeg" class="pic2"/>
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
</div>

and this the css:

.description {
    padding: 0% 2% 1% 2%;
}

.description p {
    font-size: 20px;
}

.pic2 {
    float: right;
}

I have tried the solutions here however they have not worked for me, and give the same output as the image shown

Thanks for any help

wtreston
  • 1,051
  • 12
  • 28
  • Your markup works as-is. Can you reproduce the problem? http://jsfiddle.net/isherwood/c8mabv5w/ – isherwood Nov 19 '18 at 21:34
  • 1
    Maybe you should use Lorem Ipsum text rather than absurdly long non-words for testing. :) – isherwood Nov 19 '18 at 21:36
  • @isherwood So your solution would be to use shorter words? Yes, that would work as well. I assumed that the long words were there for a reason though... – Mr Lister Nov 19 '18 at 21:41
  • I'd assume that the question would've mentioned it were that the case. Maybe not. – isherwood Nov 19 '18 at 21:42

1 Answers1

1

What you need to for the words to be breakable everywhere. So, word-break: break-all;

.description {
  padding: 0% 2% 1% 2%;
}

.description p {
  font-size: 20px;
}

.pic2 {
  float: right;
}

div {  /* new */
  word-break: break-all;
}
<div>
  <img src="https://placehold.it/400x150" class="pic2" />  slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL slasdfkasjhdfkjasdhfkjlasdhfkjlashdfkjlshdKL
</div>
Mr Lister
  • 45,515
  • 15
  • 108
  • 150