Tukkan
Tukkan

Reputation: 1625

Can i put text after <li></li> tag?

I'm wondering, can I put text after Li tag and will it be correct? Example

<ul>
    <li>Text</li>
    Text here after tag
    <li>Text</li>
    Text here after tag
</ul>

Writing such a code will return dots from li tags indented and that's what I want to achieve.

Upvotes: 3

Views: 10285

Answers (3)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201618

It is invalid to have text between li elements, by HTML syntax. But what you seem to really asking for is the rendering in your jsfiddle, which can be achieved by using markup like

<ul>
    <li>Text<br>
    Text here
    <li>Text<br>
    Text here
</ul>

and a style sheet that makes the list bullet appear “inside”:

ul { list-style-position: inside }

See my jsfiddle.

Upvotes: 0

5pike
5pike

Reputation: 176

Regarding your screenshot - the following code does what you want

<ul>
    <li>Text</li>
    <span>Text here after tag</span>
    <li>Text</li>
    <span>Text here after tag</span>
</ul>

css

span {
    margin-left: -15px;
}

And here is a fiddle: http://jsfiddle.net/P2CXF/

Note that the W3C markup validator will throw errors. The <span> tag is not allowed as child of <ul>

EDIT:

This one will validate (thank you @Ma3x)

<ul>
    <li>Text<br />
    <span>Text here after tag</span></li>
    <li>Text<br />
    <span>Text here after tag</span></li>
</ul>

You can also use <p> instead of <span>.

Upvotes: 4

Nick
Nick

Reputation: 15459

Using <br /> instead like this:

<ul>
<li>Text<br />Text here after tag</li>

<li>Text<br />Text here after tag</li></ul>

Will produce the same effect and make a little more sense semantically if all you were intending to do was break the text down to the next line.

fiddle

Upvotes: 2

Related Questions