You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.html
+22-42Lines changed: 22 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -389,78 +389,58 @@ <h4 class="exercise-start">
389
389
<li>Check out Jen Looper's article on <ahref="https://www.nativescript.org/blog/demystifying-nativescript-layouts">demystifying NativeScript layouts</a> for a more thorough look at NativeScript layouts in action.</li>
390
390
</ul>
391
391
</blockquote>
392
-
<h3id="css">CSS</h3>
393
-
<p>NativeScript uses a <ahref="http://docs.nativescript.org/styling">subset of CSS</a> to change the visual appearance of your app. You can use three mechanisms to add CSS properties to UI components: <ahref="http://docs.nativescript.org/styling#application-wide-css">application-wide CSS</a> (<code>app.css</code>), component-specific CSS, and an <ahref="http://docs.nativescript.org/styling#inline-css">inline <code>style</code> attribute</a>.</p>
392
+
<h3id="global-css">Global CSS</h3>
393
+
<p>NativeScript uses a <ahref="http://docs.nativescript.org/styling">subset of CSS</a> to change the visual appearance of your app. You can use three mechanisms to add CSS properties to UI components: <ahref="http://docs.nativescript.org/styling#application-wide-css">application-wide CSS</a> (<code>app.css</code>), component-specific CSS, and an <ahref="http://docs.nativescript.org/styling#inline-css">inline <code>style</code> attribute</a>. In this section we’ll cover application-wide, or global CSS, and in the next section we’ll look at how to apply CSS rules to individual components.</p>
394
394
<blockquote>
395
-
<p><strong>TIP</strong>: Although inline styles are great for quick testing—e.g. <code><StackLayout style="background-color: green;"></code>you should avoid them in general because the <code>style</code> attributes tend to clutter up your templates, especially if you need to apply multiple rules.</p>
395
+
<p><strong>TIP</strong>: Although inline styles are great for quick testing—e.g. <code><StackLayout style="background-color: green;"></code>—you should avoid them in general because the <code>style</code> attributes tend to clutter up your templates, especially if you need to apply multiple rules.</p>
396
396
</blockquote>
397
-
<p>Let's start by adding a few application-wide CSS rules.</p>
398
397
<h4class="exercise-start">
399
398
<b>Exercise</b>: Create global styles
400
399
</h4>
401
400
402
401
<p>Open your app’s <code>app/app.css</code> file and paste in the following code:</p>
403
402
<pre><codeclass="lang-CSS">Page {
404
403
background-color: white;
405
-
font-size: 17;
404
+
font-size: 15;
406
405
}
407
406
TextField {
408
-
margin: 10;
409
-
padding: 10;
410
-
}
411
-
Image {
412
-
margin-top: 20;
413
-
margin-left: 0;
414
-
margin-right: 0;
415
-
margin-bottom: 80;
416
-
}
417
-
Button {
418
-
margin: 10;
419
407
padding: 10;
408
+
font-size: 13;
420
409
}
421
410
</code></pre>
422
411
<divclass="exercise-end"></div>
423
412
424
-
<p>If you've done any web development before, the syntax should feel familiar here. You select four UI components (Page, TextField, Image, and Button) by their tag name, and then apply a handful of CSS rules as name/value pairs. NativeScript does not support all CSS properties because it is not possible to replicate some of them in native apps without causing performance issues. A <ahref="http://docs.nativescript.org/styling#supported-properties">full list of the CSS properties that are supported</a> are listed in the NativeScript docs.</p>
425
-
<p>Let's make one more change. Although often you want CSS rules to apply equally to your iOS and Android app, occasionally it makes sense to apply a CSS rule to only one platform. For example, iOS text fields frequently have borders around them, but Android text fields do not. Let's look at how to make platform-specific style changes in NativeScript.</p>
413
+
<p>If you've done any web development before, the syntax should feel familiar here. You select two UI components by their tag names (Page and TextField), and then apply a handful of CSS rules as name/value pairs. NativeScript does not support all CSS properties because it is not possible to replicate some of them in native apps without causing performance issues. A <ahref="http://docs.nativescript.org/styling#supported-properties">full list of the CSS properties that are supported</a> are listed in the NativeScript docs.</p>
414
+
<p>Although often you want CSS rules to apply equally to your iOS and Android app, occasionally it makes sense to apply a CSS rule to only one platform. For example, iOS text fields frequently have borders around them, but Android text fields do not. Let's look at how to make platform-specific style changes in NativeScript.</p>
426
415
<h4class="exercise-start">
427
416
<b>Exercise</b>: Add platform-specific CSS
428
417
</h4>
429
418
430
-
<p>Add the following as the first line of your app's <code>app.css</code> file:</p>
<p><strong>WARNING</strong>: NativeScript is consistent with browser implementations in that <code>@import</code> statements must precede all other CSS rules in a file.</p>
435
424
</blockquote>
436
-
<p>Next, add a <code>class="link"</code> attribute to the sign up button in <code>login/login.html</code>. The button's markup should look like this:</p>
437
-
<pre><codeclass="lang-XML"><Button text="Sign up for Groceries" class="link" />
425
+
<p>Next, open your app’s <code>app/platform.ios.css</code> file and paste in the following code:</p>
426
+
<pre><codeclass="lang-CSS">TextField {
427
+
border-width: 1;
428
+
border-color: black;
429
+
}
438
430
</code></pre>
439
431
<divclass="exercise-end"></div>
440
432
441
-
<p>Let's break down what just happened. First, NativeScript supports CSS's <code>@import</code> statement for importing one CSS file into another. So this new line of code imports the CSS rules from <code>platform.css</code> into <code>app.css</code>. But, you might have noticed that Groceries does not have a file named <code>platform.css</code>—only <code>app/platform.android.css</code> and <code>app/platform.ios.css</code> exist. What's going on here?</p>
433
+
<p>NativeScript supports CSS's <code>@import</code> statement for importing one CSS file into another. So this new line of code imports the CSS rules from <code>platform.css</code> into <code>app.css</code>. But, you might have noticed that Groceries does not have a file named <code>platform.css</code>—only <code>app/platform.android.css</code> and <code>app/platform.ios.css</code> exist. What's going on here?</p>
442
434
<p><aid="platform-specific-files"></a>When you execute <code>tns run</code>, or <code>tns livesync</code>, the NativeScript CLI takes your code from the <code>app</code> folder and places it in the native projects located in the <code>platforms/ios</code> and <code>platforms/android</code> folders. Here the naming convention comes in: while moving files, the CLI intelligently selects <code>.android.*</code> and <code>.ios.*</code> files. To give a specific example, the CLI moves <code>platform.ios.css</code> into <code>platforms/ios</code> and renames it to <code>platform.css</code>; similarly, the CLI moves <code>platform.android.css</code> into <code>platforms/android</code>, and again renames it to <code>platform.css</code>. This convention provides a convenient way to branch your code to handle iOS and Android separately, and it's supported for any type of file in NativeScript—not just CSS files. You'll see a few more examples of this convention later in this guide.</p>
443
-
<p>There's one other change here we need to discuss, and that's the <code>class</code> attribute you added to this button:</p>
444
-
<pre><codeclass="lang-XML"><Button text="Sign up for Groceries" class="link" />
445
-
</code></pre>
446
-
<p>NativeScript uses the <code>class</code> attribute for adding CSS class names to UI components. The class name is used to give the sign up button a slightly different look than the sign in button. You can find the CSS rules associated with this class name in <code>platform.ios.css</code> and <code>platform.android.css</code>:</p>
447
-
<pre><codeclass="lang-CSS">/* From platform.android.css */
448
-
.link {
449
-
background-color: transparent;
450
-
}
451
-
452
-
/* From platform.ios.css */
453
-
.link {
454
-
border-width: 0;
455
-
}
456
-
</code></pre>
457
435
<blockquote>
458
-
<p><strong>TIP</strong>: NativeScript also supports selecting elements by the <code>id</code>attribute. Refer to the docs for <ahref="/styling#supported-selectors">a full list of the supported selectors</a>.</p>
436
+
<p><strong>Note</strong>: The <code>platform.android.css</code>file is currently empty as we have no Android-specific changes to make yet. We’ll make some Android-specific tweaks later in the guide.</p>
459
437
</blockquote>
460
-
<p>With these changes in place, you'll notice that the app looks halfway decent now, and also has a distinctly different look on iOS and Android:</p>
<p>Feel free to take some time to play with the look of this app before moving on. When you're ready, let's move on and add an image to this login screen.</p>
438
+
<p>With these changes in place, you'll notice that the app has a bit more spacing, and also has a distinctly different look on iOS and Android:</p>
<p>In NativeScript you use the <code><Image></code> UI element and its <code>src</code> attribute to add images to your pages. The <code>src</code> attribute lets you specify your image in three ways. The first (and simplest) way is to point at the URL of an image:</p>
Copy file name to clipboardExpand all lines: src/chapters/chapter2.md
+23-48Lines changed: 23 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -221,13 +221,11 @@ Although the UI elements are in the correct order, they could use some spacing a
221
221
> * Refer to the NativeScript docs for a [more detailed look at how NativeScript layouts work](http://docs.nativescript.org/layouts) and the various things you can do to configure them.
222
222
> * Check out Jen Looper's article on [demystifying NativeScript layouts](https://www.nativescript.org/blog/demystifying-nativescript-layouts) for a more thorough look at NativeScript layouts in action.
223
223
224
-
### CSS
224
+
### Global CSS
225
225
226
-
NativeScript uses a [subset of CSS](http://docs.nativescript.org/styling) to change the visual appearance of your app. You can use three mechanisms to add CSS properties to UI components: [application-wide CSS](http://docs.nativescript.org/styling#application-wide-css) (`app.css`), component-specific CSS, and an [inline `style` attribute](http://docs.nativescript.org/styling#inline-css).
226
+
NativeScript uses a [subset of CSS](http://docs.nativescript.org/styling) to change the visual appearance of your app. You can use three mechanisms to add CSS properties to UI components: [application-wide CSS](http://docs.nativescript.org/styling#application-wide-css) (`app.css`), component-specific CSS, and an [inline `style` attribute](http://docs.nativescript.org/styling#inline-css). In this section we’ll cover application-wide, or global CSS, and in the next section we’ll look at how to apply CSS rules to individual components.
227
227
228
-
> **TIP**: Although inline styles are great for quick testing—e.g. `<StackLayout style="background-color: green;">` you should avoid them in general because the `style` attributes tend to clutter up your templates, especially if you need to apply multiple rules.
229
-
230
-
Let's start by adding a few application-wide CSS rules.
228
+
> **TIP**: Although inline styles are great for quick testing—e.g. `<StackLayout style="background-color: green;">`—you should avoid them in general because the `style` attributes tend to clutter up your templates, especially if you need to apply multiple rules.
231
229
232
230
<h4class="exercise-start">
233
231
<b>Exercise</b>: Create global styles
@@ -238,81 +236,58 @@ Open your app’s `app/app.css` file and paste in the following code:
238
236
```CSS
239
237
Page {
240
238
background-color: white;
241
-
font-size: 17;
239
+
font-size: 15;
242
240
}
243
241
TextField {
244
-
margin: 10;
245
-
padding: 10;
246
-
}
247
-
Image {
248
-
margin-top: 20;
249
-
margin-left: 0;
250
-
margin-right: 0;
251
-
margin-bottom: 80;
252
-
}
253
-
Button {
254
-
margin: 10;
255
242
padding: 10;
243
+
font-size: 13;
256
244
}
257
245
```
258
246
259
247
<divclass="exercise-end"></div>
260
248
261
-
If you've done any web development before, the syntax should feel familiar here. You select four UI components (Page, TextField, Image, and Button) by their tag name, and then apply a handful of CSS rules as name/value pairs. NativeScript does not support all CSS properties because it is not possible to replicate some of them in native apps without causing performance issues. A [full list of the CSS properties that are supported](http://docs.nativescript.org/styling#supported-properties) are listed in the NativeScript docs.
249
+
If you've done any web development before, the syntax should feel familiar here. You select two UI components by their tag names (Page and TextField), and then apply a handful of CSS rules as name/value pairs. NativeScript does not support all CSS properties because it is not possible to replicate some of them in native apps without causing performance issues. A [full list of the CSS properties that are supported](http://docs.nativescript.org/styling#supported-properties) are listed in the NativeScript docs.
262
250
263
-
Let's make one more change. Although often you want CSS rules to apply equally to your iOS and Android app, occasionally it makes sense to apply a CSS rule to only one platform. For example, iOS text fields frequently have borders around them, but Android text fields do not. Let's look at how to make platform-specific style changes in NativeScript.
251
+
Although often you want CSS rules to apply equally to your iOS and Android app, occasionally it makes sense to apply a CSS rule to only one platform. For example, iOS text fields frequently have borders around them, but Android text fields do not. Let's look at how to make platform-specific style changes in NativeScript.
264
252
265
253
<h4class="exercise-start">
266
254
<b>Exercise</b>: Add platform-specific CSS
267
255
</h4>
268
256
269
-
Add the following as the first line of your app's `app.css` file:
257
+
Add the following as the first line of your app's `app/app.css` file:
270
258
271
259
```CSS
272
-
@import{ url('~/platform.css') };
260
+
@importurl("~/platform.css");
273
261
```
274
262
> **WARNING**: NativeScript is consistent with browser implementations in that `@import` statements must precede all other CSS rules in a file.
275
263
276
-
Next, add a `class="link"` attribute to the sign up button in `login/login.html`. The button's markup should look like this:
264
+
Next, open your app’s `app/platform.ios.css` file and paste in the following code:
277
265
278
-
```XML
279
-
<Buttontext="Sign up for Groceries"class="link" />
266
+
```CSS
267
+
TextField {
268
+
border-width: 1;
269
+
border-color: black;
270
+
}
280
271
```
281
272
282
273
<divclass="exercise-end"></div>
283
274
284
-
Let's break down what just happened. First, NativeScript supports CSS's `@import` statement for importing one CSS file into another. So this new line of code imports the CSS rules from `platform.css` into `app.css`. But, you might have noticed that Groceries does not have a file named `platform.css`—only `app/platform.android.css` and `app/platform.ios.css` exist. What's going on here?
275
+
NativeScript supports CSS's `@import` statement for importing one CSS file into another. So this new line of code imports the CSS rules from `platform.css` into `app.css`. But, you might have noticed that Groceries does not have a file named `platform.css`—only `app/platform.android.css` and `app/platform.ios.css` exist. What's going on here?
285
276
286
277
<aid="platform-specific-files"></a>When you execute `tns run`, or `tns livesync`, the NativeScript CLI takes your code from the `app` folder and places it in the native projects located in the `platforms/ios` and `platforms/android` folders. Here the naming convention comes in: while moving files, the CLI intelligently selects `.android.*` and `.ios.*` files. To give a specific example, the CLI moves `platform.ios.css` into `platforms/ios` and renames it to `platform.css`; similarly, the CLI moves `platform.android.css` into `platforms/android`, and again renames it to `platform.css`. This convention provides a convenient way to branch your code to handle iOS and Android separately, and it's supported for any type of file in NativeScript—not just CSS files. You'll see a few more examples of this convention later in this guide.
287
278
288
-
There's one other change here we need to discuss, and that's the `class` attribute you added to this button:
279
+
> **Note**: The `platform.android.css` file is currently empty as we have no Android-specific changes to make yet. We’ll make some Android-specific tweaks later in the guide.
289
280
290
-
```XML
291
-
<Buttontext="Sign up for Groceries"class="link" />
292
-
```
293
-
294
-
NativeScript uses the `class` attribute for adding CSS class names to UI components. The class name is used to give the sign up button a slightly different look than the sign in button. You can find the CSS rules associated with this class name in `platform.ios.css` and `platform.android.css`:
295
-
296
-
```CSS
297
-
/* From platform.android.css */
298
-
.link {
299
-
background-color: transparent;
300
-
}
301
-
302
-
/* From platform.ios.css */
303
-
.link {
304
-
border-width: 0;
305
-
}
306
-
```
281
+
With these changes in place, you'll notice that the app has a bit more spacing, and also has a distinctly different look on iOS and Android:
307
282
308
-
> **TIP**: NativeScript also supports selecting elements by the `id` attribute. Refer to the docs for [a full list of the supported selectors](/styling#supported-selectors).
283
+

284
+

309
285
310
-
With these changes in place, you'll notice that the app looks halfway decent now, and also has a distinctly different look on iOS and Android:
286
+
Despite our changes, the app still doesn’t look great, and that’s because we’re going to apply another batch of styles at the component level.
311
287
312
-

313
-

288
+
### Component-specific CSS
314
289
315
-
Feel free to take some time to play with the look of this app before moving on. When you're ready, let's move on and add an image to this login screen.
0 commit comments