Steven
Steven

Reputation: 25304

Is there an elegant way to make/generate spaces instead of &nbsp?

I need to generate spaces in a HTML file.

Upvotes: 2

Views: 6586

Answers (7)

Orson
Orson

Reputation: 15431

Yacoby is right. But i have something different:

<head>

<style type="text/css">
    .left-space { margin-left: 10px; }
</style>

</head>

<body>

<div>
   <p>This is a test line.<span class="left-space">This is a line with space before it.</span></p>
</div>

</body>

And by the way you should replace &nbsp; with &#160; to conform to XHTML.

Upvotes: 0

yoav barnea
yoav barnea

Reputation: 5994

just do:

/* in your css code:  */ 
pre
{
  display:inline;   
}
<!-- and then, in your HTML markup: -->

<pre>    this text comes after 4 spaces.</pre>
<span> continue the line with other element without braking </span>

Upvotes: 0

Karim
Karim

Reputation: 6283

i use a span with css classes.
i have several class like spacer_1, spacer_2, spacer_3, etc..
i use different horizontal padding like this

.spacer_1
{
    padding:0px 5px;
}

to use this spacer you can use the following

<span class="spacer_1" /> /*this will generate half the gap*/
<span class="spacer_1"></span>
<span class="spacer_1">|</span>

Upvotes: 0

jeroen
jeroen

Reputation: 91734

It all depends on the context, you can use letter-spacing, word-spacing or for example padding for surrounding span's.

Without more information it´s impossible to give a good advice.

Edit: if it´s for use in texts / in between words, I´d go for the word-spacing and perhaps letter-spacing.

Upvotes: 6

Yacoby
Yacoby

Reputation: 55445

Use either &nbsp or <pre> tags. The <pre> tag preserves all spaces, tabs and newlines.

EDIT
Regarding your comment about its use, for padding, you may want to look at css padding

Upvotes: 13

eozzy
eozzy

Reputation: 68670

I hardly ever use &nbsp;

margin and padding properties work well for spacing and <br /> for newlines. (I don't use <br /> too frequently either.)

Upvotes: 1

James Brooks
James Brooks

Reputation: 1311

&nbsp; is a non-breaking space. Alternatively I guess you could use a <br /> (XHTML there) tag just to generate a new line.

Upvotes: 0

Related Questions