-
Book Overview & Buying
-
Table Of Contents
Server-Side Enterprise Development with Angular
By :
The default generated Angular application does not have any styling. Angular does not dictate anything in terms of style. This means that in your own projects you can use any CSS framework like Bootstrap, Angular Material, Foundation, Semantic UI, or one of the many others.
Alternatively, it's possible to create a custom style from scratch to get a unique look and feel. For this book, though, we will stick to Bootstrap 4 and Font Awesome, as they are widely used and provide a decent style with a minimal amount of code.
Font Awesome is a so-called icon font. You can include it in your page and then use it to show icons by applying some classes to an empty <i class=""></i> tag.
As mentioned in the previous section, the application has a global stylesheet named src/styles.css.
In this stylesheet, we will use the @import command to link to Bootstrap and Font Awesome. This will instruct Angular to download those files and apply the style to the application globally.
For a list of all available icons, you can refer to the Font Awesome icon list at https://fontawesome.com/v4.7.0/icons/. For an overview of all available Bootstrap styles, you can refer to the Bootstrap 4 documentation at https://getbootstrap.com/docs/4.1/getting-started/introduction/. To easily apply a different theme to the app, you can switch out Bootstrap with one of the BootSwatch themes at https://www.bootstrapcdn.com/bootswatch/.
In this exercise, we will add Bootstrap and Font Awesome to the global stylesheet. Follow these steps to complete this exercise:
src/styles.css file in the editor.@import url('');url( ) function.@import url('');url( ) function:
As you can see, the font of the application got updated to a sans serif font, as that's the Bootstrap default.
In this exercise, we will update the template of AppComponent to show that Font Awesome works. Follow these steps to complete this exercise:
src/app.component.html file and replace its content with the following:<h1 class="text-center mt-5"> <i class="fa fa-thumbs-up"></i> </h1>
We can change the default Bootstrap theme with a different one. The BootSwatch Themes project (https://www.bootstrapcdn.com/bootswatch/) provides a lot of colorful themes that are a drop-in replacement for Bootstrap. This means that all of the Bootstrap CSS selectors will work — they just look different! In this activity, we will use a different theme for our app.
The steps are as follows:
src/styles.css.The solution for this activity can be found on page 108.
Font Awesome comes with a large amount of icons that you can use once you've included the file. In this activity, we will use a different icon than the thumbs-up icon we have used already.
The steps are as follows:
src/app/app.component.html file.fa-thumbs-up with another icon. Note that you always need the fa class.The solution for this activity can be found on page 109.
Change the font size
Change margin width
Change background colour