teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

2019/11/17 21:54

投稿

taiyakix
taiyakix

スコア427

title CHANGED
File without changes
body CHANGED
@@ -118,7 +118,7 @@
118
118
  ```
119
119
  上記の状態で右と左にアイコンが並ぶのですが、その間に
120
120
  ```html
121
- <p style="text-align: center;"id="time">a</p>
121
+ <h1 id="time"></h1>
122
122
  ```
123
123
  を挟みたいのですが、
124
124
  ```html

1

コードの全文とcodepenのサンプルを追記しました。

2019/11/17 21:54

投稿

taiyakix
taiyakix

スコア427

title CHANGED
File without changes
body CHANGED
@@ -1,13 +1,155 @@
1
1
  ```html
2
+ <!DOCTYPE HTML>
3
+ <html>
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
7
+ <meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
8
+ <script src="components/loader.js"></script>
9
+ <script src="lib/onsenui/js/onsenui.min.js"></script>
10
+
11
+ <link rel="stylesheet" href="components/loader.css">
12
+ <link rel="stylesheet" href="lib/onsenui/css/onsenui.css">
13
+ <link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css">
14
+ <link rel="stylesheet" href="css/style.css">
15
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
16
+
17
+ <script>
18
+ ons.ready(function(){
19
+ document.addEventListener('init', function(event) {
20
+ time();
21
+ setInterval(time,1000);
22
+ }, false);
23
+ });
24
+
25
+ function time(){
26
+ var now = new Date();
27
+ document.getElementById("time").innerHTML = now.toLocaleTimeString();
28
+ }
29
+ ons.ready(function() {
30
+ console.log("Onsen UI is ready!");
31
+ });
32
+
33
+ window.fn = {};
34
+ window.fn.open = function() {
35
+ var menu = document.getElementById('menu');
36
+ menu.open();
37
+ };
38
+ window.fn.load = function(page) {
39
+ var content = document.getElementById('content');
40
+ var menu = document.getElementById('menu');
41
+ content
42
+ .load(page)
43
+ .then(menu.close.bind(menu));
44
+ };
45
+
46
+ if (ons.platform.isIPhoneX()) {
47
+ document.documentElement.setAttribute('onsflag-iphonex-portrait', '');
48
+ document.documentElement.setAttribute('onsflag-iphonex-landscape', '');
49
+ }
50
+ </script>
51
+ </head>
52
+ <body>
53
+ <ons-splitter>
54
+ <ons-splitter-side id="menu" side="left" width="220px" collapse swipeable>
55
+ <ons-page>
56
+ <ons-list>
57
+ <ons-list-item onclick="fn.load('home.html')" tappable>
58
+ <h5><i style="float: left;"class="material-icons blue">home</i>Home</h5>
59
+ </ons-list-item>
60
+ <ons-list-item onclick="fn.load('settings.html')" tappable>
61
+ <h5><i style="float: left;"class="material-icons blue">settings</i>Settings</h5>
62
+ </ons-list-item>
63
+ <ons-list-item onclick="fn.load('about.html')" tappable>
64
+ <h5><i style="float: left;"class="material-icons blue">pie_chart</i>Chart</h5>
65
+ </ons-list-item>
66
+ <ons-list-item onclick="fn.load('about.html')" tappable>
67
+ <h5><i style="float: left;"class="material-icons blue">help_outline</i>How To</h5>
68
+ </ons-list-item>
69
+ </ons-list>
70
+ </ons-page>
71
+ </ons-splitter-side>
72
+ <ons-splitter-content id="content" page="home.html"></ons-splitter-content>
73
+ </ons-splitter>
74
+
75
+ <ons-template id="home.html">
76
+ <ons-page>
2
77
  <ons-toolbar-button onclick="fn.open()">
3
78
  <i style="float: left;"class="material-icons bigblue">reorder</i>
4
79
  </ons-toolbar-button>
5
80
  <i style="float: right;"class="material-icons bigblue">help_outline</i>
81
+ <h1 id="time"></h1>
82
+ </ons-page>
83
+ </ons-template>
84
+
85
+ <ons-template id="settings.html">
86
+ <ons-page>
87
+ <ons-toolbar>
88
+ <div class="left">
89
+ <ons-toolbar-button onclick="fn.open()">
90
+ <ons-icon icon="ion-navicon, material:md-menu"></ons-icon>
91
+ </ons-toolbar-button>
92
+ </div>
93
+ <div class="center">
94
+ Settings
95
+ </div>
96
+ </ons-toolbar>
97
+ </ons-page>
98
+ </ons-template>
99
+
100
+ <ons-template id="about.html">
101
+ <ons-page>
102
+ <ons-toolbar>
103
+ <div class="left">
104
+ <ons-toolbar-button onclick="fn.open()">
105
+ <ons-icon icon="ion-navicon, material:md-menu"></ons-icon>
106
+ </ons-toolbar-button>
107
+ </div>
108
+ <div class="center">
109
+ About
110
+ </div>
111
+ </ons-toolbar>
112
+ </ons-page>
113
+ </ons-template>
114
+
115
+ </body>
116
+ </html>
117
+
6
118
  ```
7
119
  上記の状態で右と左にアイコンが並ぶのですが、その間に
8
120
  ```html
9
121
  <p style="text-align: center;"id="time">a</p>
10
122
  ```
11
- を挟みたいのですが、どうもうまくいきません。
123
+ を挟みたいのですが、
124
+ ```html
125
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
126
+ <div class="f-container">
127
+ <div class="f-item"><ons-toolbar-button onclick="fn.open()">
128
+ <i style="float: left;"class="material-icons bigblue">reorder</i>
129
+ </ons-toolbar-button></div>
130
+ <div class="f-item"><h1 id="time">a</h1></div>
131
+ <div class="f-item"><i style="float: right;"class="material-icons bigblue">help_outline</i></div>
132
+ </div>
133
+ ```
134
+ 上記のコードと
135
+ ```css
136
+ .f-container {
137
+ display:flex;
138
+ flex-diretion: row;
139
+ }
140
+ ```
141
+ ```js
142
+ ons.ready(function(){
143
+ document.addEventListener('init', function(event) {
144
+ time();
12
- これだけだと丸投げの質問に見えるのは申し訳なく思います。
145
+ setInterval(time,1000);
146
+ }, false);
147
+ });
148
+
149
+ function time(){
150
+ var now = new Date();
151
+ document.getElementById("time").innerHTML = now.toLocaleTimeString();
152
+ }
153
+ ```
154
+ と[codepen](https://codepen.io/TaiyakiX/pen/VwwqLqW)にかいたのですが、見ればわかるとおりまず時間が表示されないのと、<h1></h1>の中だけ少し低くなってしまいます。これを直すにはどうすればいいでしょうか。
13
155
  Monacaで動かすのを前提でお願いします。