Sanket
Sanket

Reputation: 149

problem in displaying span in HTML

I am creating nested spans as follows:

<span id="1">
   text1
   <span id="2"> text 2</span>
</span>

But somehow text 2 is being desplayed on new line , may be it is styles sheet issue but i cant chnage style sheet due to some other resons.How can i overide default style sheet and make text 2 to be displayed on same line as text1

Upvotes: 2

Views: 734

Answers (5)

Evn
Evn

Reputation: 1

Try using the following: display:inline.

Upvotes: -1

akamike
akamike

Reputation: 2158

It is likely the stylesheet has set spans to display:block which causes them to take their own line, such as the default styling for a div. To fix this you can add a style attribute:

<span id="1">
   text1
   <span id="2" style="display:inline"> text 2</span>
</span>

However, this may still be overridden by the stylesheet if it is using the !important flag.

For future debugging I recommend you look at tools like Web Inspector (Safari and Chrome), Firebug (Firefox) and Dragonfly (Opera). One final note, you can't have an id attribute that begins with a number, it must start with a letter.

Upvotes: 1

alex
alex

Reputation: 490333

If they are not displaying one next to the other, then some of your CSS is setting its display: block (or similar) and not display: inline.

Easy fix - inspect the CSS setting it and remove, or explicitly state display: inline on that element.

Also, valid id (and name for that matter) attributes must start with a [a-zA-Z].

Upvotes: 1

x2.
x2.

Reputation: 9668

try <span id="2" style="display:inline;">

Upvotes: 1

thedev
thedev

Reputation: 2906

<span style="display:inline;">

Upvotes: 1

Related Questions