0

I've created a text, and added some left floated boxes to it. But for some reason, they behave differently. The first box breaks the line before it, but the second one doesn't. I don't understand, why. JSFiddle: https://jsfiddle.net/qt9q7dn4/

(thie green colored texts are the words after the red boxes)

test

CSS:

div {
    width: 50px;
    height: 50px;
    background: red;
    float: left;
    margin: 5px;
}

.after {
    color: lime;
    font-weight: bold;
}

HTML:

<p>Lorem 
<div></div> 
<span class="after">ipsum</span> 
dolor sit amet, consectetur adipiscing elit. Duis sed nibh gravida, euismod leo ultrices, auctor nulla. Fusce nunc ante, condimentum in ex sit amet, pharetra vestibulum urna. Morbi vitae bibendum enim, vitae congue eros. Sed dignissim magna id tincidunt posuere.Duis sed nibh gravida, euismod leo ultrices, auctor nulla. Fusce nunc ante, condimentum in ex sit amet, pharetra vestibulum urna. Morbi vitae bibendum enim, vitae congue eros. Sed dignissim magna id tincidunt posuere.In magna ante, luctus sit amet nulla eget, gravida convallis nisi. Curabitur et blandit felis, 
<div></div> 
<span class="after">vitae
</span> facilisis nibh. Integer eu eros 
vitae est tristique tincidunt quis pulvinar mi. Duis sed nibh gravida, euismod leo ultrices, auctor nulla. Fusce nunc ante, condimentum in ex sit amet, pharetra vestibulum urna. Morbi vitae bibendum enim, vitae congue eros. Sed dignissim magna id tincidunt posuere.</p>
3
  • <p><div></div></p> is not valid markup.
    – Scott
    Commented Sep 1, 2016 at 20:58
  • 2
    (For more on that, see the excellent answer to stackoverflow.com/questions/8397852/…)
    – henry
    Commented Sep 1, 2016 at 21:02
  • Your <div> floats, but that doesn't mean your <p> will be interupted. You could start a new paragraph tag in which you start with your floating div.
    – meavo
    Commented Sep 1, 2016 at 21:05

1 Answer 1

0

Move the divs outside the paragraphs and close the paragraphs.

<div></div>

<p>Lorem  <span class="after">ipsum</span> dolor sit amet, consectetur adipiscing elit. Duis sed nibh gravida, euismod leo ultrices, auctor nulla. Fusce nunc ante, condimentum in ex sit amet, pharetra vestibulum urna. Morbi vitae bibendum enim, vitae congue eros. Sed dignissim magna id tincidunt posuere.Duis sed nibh gravida, euismod leo ultrices, auctor nulla. Fusce nunc ante, condimentum in ex sit amet, pharetra vestibulum urna. Morbi vitae bibendum enim, vitae congue eros. Sed dignissim magna id tincidunt posuere.In magna ante, luctus sit amet nulla eget, gravida convallis nisi. Curabitur et blandit felis, </p>

<div></div> 

<p><span class="after">vitae</span> facilisis nibh. Integer eu eros vitae est tristique tincidunt quis pulvinar mi. Duis sed nibh gravida, euismod leo ultrices, auctor nulla. Fusce nunc ante, condimentum in ex sit amet, pharetra vestibulum urna. Morbi vitae bibendum enim, vitae congue eros. Sed dignissim magna id tincidunt posuere.</p>

Fiddle

2
  • 1
    Splitting a paragraph at the middle of a sentence is clearly not semantic.
    – Oriol
    Commented Sep 1, 2016 at 21:36
  • .. ...because Lorem Ipsum text is meant to be read and understood by viewers?
    – Scott
    Commented Sep 1, 2016 at 21:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.