官术网_书友最值得收藏!

Adding headers

You've already worked with headers in the previous chapter, so the code will be familiar. In this chapter, we will study them deeper and demonstrate how to add additional functionality, such as buttons, to your website headers.

If you remember, a header block can be defined by simply using a p tag with the appropriate role:

<p data-role="header"><h1>My Header</h1></p>

We can further add functionality to headers by adding buttons. Buttons could be used for navigation (for example, to return to the home screen) or to provide links to related pages. Because the center of the header is used for text, there are only two spaces available for buttons—one to the left and one to the right. Buttons can be added simply by creating links in your header. The first link will be to the left of the text and the second link to the right. The following file is an example:

Listing 3-1: header_test.html
<p data-role="header">
  <a href="index.html">Home</a>
  <h1>My Header</h1>
  <a href="contact.html">Contact</a>
</p>

When viewed in the mobile browser, you can see that the links were automatically turned into buttons:

Notice how the simpler links were automatically turned into big buttons, making them easier to use and more control-like for the header. You may be wondering what if you only want one button on the right-hand side? Removing the first button and keeping the second in its place will not work, as shown in the following code snippet:

<p data-role="header">
  <h1>My Header</h1>
  <a href="contact.html">Contact</a>
</p>

The previous code snippet creates a button in the header but on the left-hand side. In order to position the button to the right, simply add the ui-btn-right class:

Listing 3-2: header_test2.html
<p data-role="header">
  <h1>My Header</h1>
  <a href="contact.html" class="ui-btn-right">Contact</a>
</p>

You can also specify ui-btn-left to place a link on the left-hand side, but as demonstrated in the previous code snippet, that's the normal behavior:

主站蜘蛛池模板: 元阳县| 中阳县| 青川县| 六盘水市| 汉阴县| 灵璧县| 宁德市| 台中市| 西和县| 雅江县| 鹤峰县| 崇阳县| 延安市| 湖南省| 天祝| 仪陇县| 乌兰察布市| 特克斯县| 乐安县| 吐鲁番市| 长岛县| 石景山区| 桐柏县| 泊头市| 寿宁县| 永新县| 桐乡市| 浦东新区| 新宁县| 建始县| 尤溪县| 绩溪县| 辛集市| 乌恰县| 和政县| 措勤县| 绥滨县| 泰来县| 青铜峡市| 犍为县| 昌黎县|