Click to See Complete Forum and Search --> : html code help required
sun_rise
08-23-2007, 06:54 AM
i have 2 requirements
(1) i have a text field ...when i enter data into it ..it has to be left-aligned.
(2)i have a <span id="result"></span> ....and in that blank space i put data via innerHTML ....i want that data also left aligned.
what code i need to use .
kindly , please tell seperately
Data is left-aligned by default, unless you have changed it.
Centauri
08-23-2007, 07:17 AM
The text in these cases should be left aligned by default, unless this is being over-ridden by the properties of a parent element. In case the parent element's text align cannot be changed, then text-align:left; applied to the particular element's style will fix that.
sun_rise
08-23-2007, 07:23 AM
sorry , i need that right.
this is not right aligned
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<input type="text" text-align:right value="20" size="30">
</BODY>
</HTML>
Centauri
08-23-2007, 07:27 AM
<input type="text" value="20" size="30" style="text-align:right">
sun_rise
08-23-2007, 07:35 AM
its working :)
one more thing..
can i use this style="text-align:right" in the span tag as well ?
because i am using innerHTML and putting data into some span tag ...i want that data to be placed right aligned there also.
Centauri
08-23-2007, 07:47 AM
Yes.
If you want this style to apply to more than one item, instead of using inline styling, you could assign the items a class and set the align property of that class either in a css style block within the page head, or an external css file.
sun_rise
08-23-2007, 08:14 AM
damn...that did not worked
i tried this way
Result: <span id="result" style="text-align:right">value_is_coming_here_from_innerHTML</span>
but did not find the Result thingie right aligned.
whats wrong ?
span is an inline element. It's length is the same as the text, so align will not work.
sun_rise
08-23-2007, 08:27 AM
i need like this
WebJoel
08-23-2007, 08:39 AM
Can you provide an example of how you are using this? A SPAN is used inside of a parent element (usually a "<p></p>"). It inherits the height of the parent, and is it's own width. Perhaps though, stating a width="" for the SPAN and using left-or-right padding might acheive something (or then again, even text-align:right might work if the SPAN is given a WIDTH), but I wonder if semantically, this is okay to do?
Seeing the context by way of example would help.
Centauri
08-23-2007, 08:47 AM
As already noted by Fang, a span will only be the length of the contents - to assign a greater width, you would have to set it to block display which defeats the purpose of a span - better off to use a div in that case. As WebJoel requested, we need to see an example (even a picture) of what you want.