Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply space in span element

Tags:

html

I have been trying to apply one white space inside the span element, but couldn't able to do it.

In my application i have the following two span elements.

<span style='color:red;margin-right:1.25em'>*</span> 
<span style='color:red;margin-right:1.25em'>&nbsp;</span>

Applied these two spans to different fields to get them in to the same alignment level, but i have the following problem. PFB enter image description here

is there any thing wrong with the above code

the first name field should move a bit right for the proper alignment.

like image 378
Jagadeesh Avatar asked Jul 27 '12 10:07

Jagadeesh


People also ask

How do I add a space between span tags?

Try: margin: 10px or similar in the span styles. That gives you a space. If you need more than one whitespace, you can use &nbsp; entity.

Can you add margin to span?

Since span tags are inline, not block elements. They can only take margin left and right, not top and bottom.

Can we add width to span?

The main thing to remember about a span element is that it is an inline element, which means that you will not be able to set the width or height of it as is.

How do I add a space between elements in CSS?

The CSS padding properties are used to generate space around an element's content, inside of any defined borders. With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).


2 Answers

margin is applied to block or inline-block elements

but not inline element like

span tags

try this

<span style='color:red;margin-right:1.25em; display:inline-block;'>&nbsp;</span>
like image 198
jwchang Avatar answered Sep 30 '22 02:09

jwchang


Since span elements are inline elements by default, horizontal margins are ignored for them by the spec. You can make them inline blocks (supported by most, but not all, browsers), or use padding instead of margin.

This probably won’t solve the ultimate problem, as the characters “*” and the no-break space are not of the same width, except by accident. To set up a table of data consisting of form fields and associated labels and explanations, use an HTML table, and then just add a little styling in CSS.

like image 26
Jukka K. Korpela Avatar answered Sep 30 '22 02:09

Jukka K. Korpela