寫 jQuery Mobile 頁面時,常會遇到內容沒有邊距、緊貼著瀏覽器邊緣的狀況,看起來相當擁擠難看(如下圖)。

修改前的程式碼:
<body>
<form id="form1" runat="server">
<div data-role="page" id="page">
<div data-role="header" data-theme="b">
<h2>新聞內容</h2>
</div>
<div>
<div>
<asp:Image ID="newsImage" runat="server" AlternateText="新聞圖片" />
</div>
<div>
<asp:Label ID="lblDetail" runat="server" Text="Label"></asp:Label>
</div>
</div>
<div data-role="footer" data-theme="d">
<h4>餐飲咨詢</h4>
</div>
</div>
</form>
</body>
其實原因很簡單:內容沒有被放進 content 容器裡。只要在對應的 div 加上 data-role="content",jQuery Mobile 就會自動套用內距:
<body>
<form id="form1" runat="server">
<div data-role="page" id="page">
<div data-role="header" data-theme="b">
<h2>新聞內容</h2>
</div>
<div data-role="content">
<div>
<asp:Image ID="newsImage" runat="server" AlternateText="新聞圖片" />
</div>
<div>
<asp:Label ID="lblDetail" runat="server" Text="Label"></asp:Label>
</div>
</div>
<div data-role="footer" data-theme="d">
<h4>餐飲咨詢</h4>
</div>
</div>
</form>
</body>
加上 data-role="content" 後,內容就會自動與邊緣拉出適當距離,版面立刻清爽許多。