Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding a word break between a text node and span in existing markup (CSS only)

As per title, I need a CSS-only solution to word break a text node and an inline element.

This is what it looks like: the left padding is split by the word break in the :before content. I obviously need to have the word break go before the before so the left padding is reunited with the rest of the element.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m injecting CSS into an existing app to pretty it up, so changing the HTML/generated HTML is a no-go.

I’ve tried all manner of break-before, different content white space characters, display: absolute, etc.

Repro here: https://jsfiddle.net/xf4y98ae/

Thanks.

.container {
  width: 100px;
  border: 1px solid grey;
}

.badge {
  margin-left: 4px;
  background-color: grey;
  padding: 2px 6px;
}

.badge:before {
  content: ' ';
}
<div class="container">
  <h3 class="title">
    Title text<span class="badge">Badge</span>
  </h3>
</div>

>Solution :

You can use the display properties

.badge {
  display: inline-block;
}

Elements with badge classes will be considered as distinct sections.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading