Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this listview positioned above the previous <p>?

I'm creating a page with jQuery Mobile and I have the following HTML:

<div data-role="page" id="page1">

    <div data-role="header">
        <h1>Page 1</h1>
    </div>

    <div data-role="content">
        <p>You need to select a page:</p>

        <ol data-role="listview">
            <li><a href="#page2">Item 1</a></li>
            <li><a href="#page2">Item 2</a></li>
        </ol>
    </div>
</div>

<div data-role="page" id="page2">

    <div data-role="header">
        <h1>Page 2</h1>
    </div>

</div>

It behaves as expected, except that on Chrome 10.0.648.205, I see the following:

enter image description here

Notice that the <p> is obscured by the list. Why is the list overlapping the text?

Note: you can play with the code here: http://jsfiddle.net/r2whr/

like image 443
Nathan Osman Avatar asked Feb 03 '26 13:02

Nathan Osman


2 Answers

For some reason, the listview's margin is defaulting to -15px all around. Just set the listview ol's margin to 0:

<ol data-role="listview" style="margin:0;">
    <li><a href="#page2">Item 1</a></li>
    <li><a href="#page2">Item 2</a></li>
</ol>

(Or just set the top margin to 0 if you still want the -15px margin around the rest of the list.)

like image 66
BraedenP Avatar answered Feb 06 '26 07:02

BraedenP


Alternatively you could use the list divider instead of the p tag (Just theme it) like this:

http://jsfiddle.net/r2whr/4/

<div data-role="content">
   <!-- <p>You need to select a page:</p> -->

    <ol data-role="listview">
        <li data-role="list-divider">You need to select a page:</li> 
        <li><a href="#page2">Item 1</a></li>
        <li><a href="#page2">Item 2</a></li>
    </ol>
</div>
like image 23
Phill Pafford Avatar answered Feb 06 '26 06:02

Phill Pafford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!