0

My html looks something like this:

<p>blah blah blah blah blah blah <b>something that I want 
on a single line</b> blah blah blah</p>

I want to somehow communicate that I want the bold section to start a new line if and only if it can't fit onto the current line. Basically I need a way to say "don't split this across lines if theres any possible way to avoid it"

Is there any facility in html or css to express this?

4 Answers 4

7

Try setting white-space: nowrap; on the <b> tag.

Sign up to request clarification or add additional context in comments.

1 Comment

That does it. &nbsp; works too, but this is easier to implement and easier to read.
1

You can add non-breaking spaces - &nbsp; - between the words, i.e.

<p>blah blah blah blah blah blah
<b>something&nbsp;that&nbsp;I&nbsp;want&nbsp;on&nbsp;a&nbsp;single&nbsp;line</b> blah blah blah</p>

Comments

0

You can use non breaking spaces between the words by using &nbsp;.

Comments

0

You can use the CSS white-space property with the nowrap value to acheive this.

In your case:

b{
    white-space:nowrap;
}

I'd recommend using the <strong> tag rather than the <b> also since the former is semantically more correct.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.