1

I'm trying to prevent period and other punctuation characters after inline blocks (with a specific class) from being wrapped to the next line. I want to avoid wrapping the inline block and subsequent punctuation it in a no-wrap-styled tag, since that requires knowing in advance where all of these situations might come up and I do not know that. I could use JavaScript to inject that structure everywhere it's needed, but I'd like to avoid it if possible, since my intuition is that that could get messy.

It is a requirement to preserve the background and padding, so display: contents will not work:

display: contents makes that the div doesn’t generate any box, so its background, border and padding are not rendered. However the inherited properties like color and font have effect on the child (span element) as expected.

My two-part question is this: can this be done without a tag around the inline-block and punctuation, and, if so, how?

Screenshot (from Firefox 62 on macOS 10.13.6) in case rendering differences mask the problem:

enter image description here

div {
  width: 309px;
  background: #EEE;
}

span.help-block {
  width: 111px;
  background: #DDD;
}

span.inline-code {
  display: inline-block;
  background: #CCC;
  color: #333;
  padding-left: 4px;
  padding-right: 4px;
  padding-top: 1px;
  margin-top: -1px;
  padding-bottom: 1px;
  margin-bottom: -1px;
  font-family: Courier, Monaco, monospace;
  font-size: .9em;
}
<div>
  <span class="help-block">To escape commas, put quotes around the value, e.g., <span class="inline-code">a,b,c,"a,b,c"</span>. To escape those quotes, double them, e.g., <span class="inline-code">a,b,"a,""b"",c"</span>.</span>
</div>

https://jsfiddle.net/don01001100/ravjykdb/9/

Becca Dee
  • 1,530
  • 1
  • 24
  • 51
  • solutions here https://stackoverflow.com/questions/10473164/preventing-line-break-after-span-style-displayinline-block – Garr Godfrey Sep 16 '18 at 02:32
  • 1
    Possible duplicate of [Preventing line break after ](https://stackoverflow.com/questions/10473164/preventing-line-break-after-span-style-displayinline-block) – Garr Godfrey Sep 16 '18 at 02:33
  • Hey, @GarrGodfrey. I did see that question, but the two solutions are unacceptable. I've updated my question to make my requirements more clear: no wrapper tag and preserve the background color and padding. – Becca Dee Sep 16 '18 at 02:41
  • i have no clue what you're question is, can you clarify? – Chris Li Sep 16 '18 at 04:54
  • Using the HTML `
    Here are quotations marks: "Quotes".
    `, is it possible to prevent the period character from wrapping independent of the span and how if so?
    – Becca Dee Sep 16 '18 at 04:56

0 Answers0