Thursday, August 2, 2018
In this tutorial we will add icons to your navbar. In the previous tutorial we added a responsive layout with bootstrap. In this post we will add some icons to your navigation. Font-Awesome gives you professional looking vector graphics, which are implemented using CSS. Bootstrap 4 uses Font-Awesome as it's icons. Glyphaicons will goes away. So we might as start using it.
Just to review this is how our layout looks like in our previous post.
We are going to add font-awesome icons to the first level of the navigation links. You can decide what icons goes into the products drop down menu.
Here are the steps to add font-awesome to our project:
1. Open the NorthwindCafe.Web project and add the font-awesome library by launching the Nuget Package manager by right-clicking on the "References" node and select "Manage NuGet Packages".
2. Once the Nuget Package manager is opened make sure the "Browse" tab is selected, then type "font-awesome" in the search box. Select the result that says "Font Awesome for Twitter Bootstrap"
3. Click the "Install" button, click "OK" in the "Preview Changes" dialog
4. We are ready to add some icons to your navbars now. Font-awesome is really easy to use first we need reference the font-awesome.css file. We could create a new Bundle Config for the font-awesome, but it is much easier to it in in our _Layout.cshtml file so that we can use it through out the site. Add the following line to between the <head> section of the layout page.
Your head markup should look like the following
5. Navigate to the font-awesome icons page to see which icons you want to use at http://fontawesome.io/icons/
6. For the "Home" icon we will use the "home" icon in font-awesome
7. If you click on the text link or the icon itself you will see the code to implement the icon in your website
To add a font-awesome to your website you just need the <i> tag with the class being the font-awesome class name for the icon that you want. Since the home icon has a class name of "fa-home", the markup is <i class="fa-home"></i>, the aria-hidden="true" is for assistance accessibility technology to ignore it. So that it does not announce the the icon to the world, since it's purpose is only for decoration and has no other meaning.
8. To add the home icon to the NorthwindCafe.Web project, open the _Layout.cshtml page. Then next to the home navigation link add the icon with the following code.
The navigation should now look like this
9. I have choose the fa-coffee for "About", fa-envelope for "Contact" and fa-product-hunt for "Products"
The navigation should look like this in desktop mode
And look like the following in mobile mode:
Your final markup should look like the following:
Similar Posts:
Just to review this is how our layout looks like in our previous post.
We are going to add font-awesome icons to the first level of the navigation links. You can decide what icons goes into the products drop down menu.
Here are the steps to add font-awesome to our project:
1. Open the NorthwindCafe.Web project and add the font-awesome library by launching the Nuget Package manager by right-clicking on the "References" node and select "Manage NuGet Packages".
2. Once the Nuget Package manager is opened make sure the "Browse" tab is selected, then type "font-awesome" in the search box. Select the result that says "Font Awesome for Twitter Bootstrap"
3. Click the "Install" button, click "OK" in the "Preview Changes" dialog
<link href="~/Content/font-awesome.min.css" rel="stylesheet" />
Your head markup should look like the following
<head> <title>@Page.Title</title> @RenderSection("head", required: false) <link href="~/Content/font-awesome.min.css" rel="stylesheet" /> @Styles.Render("~/Content/bootstrap") @Styles.Render("~/Content/css") </head>
5. Navigate to the font-awesome icons page to see which icons you want to use at http://fontawesome.io/icons/
6. For the "Home" icon we will use the "home" icon in font-awesome
7. If you click on the text link or the icon itself you will see the code to implement the icon in your website
To add a font-awesome to your website you just need the <i> tag with the class being the font-awesome class name for the icon that you want. Since the home icon has a class name of "fa-home", the markup is <i class="fa-home"></i>, the aria-hidden="true" is for assistance accessibility technology to ignore it. So that it does not announce the the icon to the world, since it's purpose is only for decoration and has no other meaning.
8. To add the home icon to the NorthwindCafe.Web project, open the _Layout.cshtml page. Then next to the home navigation link add the icon with the following code.
<li class="nav-item active"> <a class="nav-link" href="#"><i class="fa fa-home"> Home</i><span class="sr-only">(current)</span></a> </li>
The navigation should now look like this
9. I have choose the fa-coffee for "About", fa-envelope for "Contact" and fa-product-hunt for "Products"
The navigation should look like this in desktop mode
And look like the following in mobile mode:
Your final markup should look like the following:
<!DOCTYPE html> <html> <head> <title>@Page.Title</title> @RenderSection("head", required: false) <link href="~/Content/font-awesome.min.css" rel="stylesheet" /> @Styles.Render("~/Content/bootstrap") @Styles.Render("~/Content/css") </head> <body> <header> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto font-weight-bold"> <li class="nav-item active"> <a class="nav-link" href="#"><i class="fa fa-home"> Home</i><span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="#"><i class="fa fa-coffee"> About</i></a> </li> <li class="nav-item"> <a class="nav-link" href="#"><i class="fa fa-envelope"> Contact</i></a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-product-hunt"> Products </i> </a> <div class="dropdown-menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item" href="#">Beverages</a> <a class="dropdown-item" href="#">Condiments</a> <a class="dropdown-item" href="#">Confections</a> <a class="dropdown-item" href="#">Dairy Products</a> <a class="dropdown-item" href="#">Grains/Cereals</a> <a class="dropdown-item" href="#">Meat/Poultry</a> <a class="dropdown-item" href="#">Produce</a> <a class="dropdown-item" href="#">Seafood</a> </div> </li> </ul> </div> </nav> <div class="jumbotron" id="header-jumbotron"> <h2>Northwind Store</h2> </div> </header> @RenderBody() @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") </body> </html>
Similar Posts:
- ASP.NET MVC Empty Project : Adding BundleConfig From Scratch
- ASP.NET MVC : Configure The BundleConfig Class To Use CDN
- ASP.NET MVC : Create A Responsive Layout With Bootstrap
- End-to-End ASP.NET MVC: Create A Responsive Layout With Bootstrap
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Đặt vé máy bay tại Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ
về việt nam từ mỹ
vé máy bay từ canada về việt nam
khi nào có máy bay từ nhật về việt nam
gia ve may bay tu han quoc ve viet nam
Vé máy bay từ Đài Loan về Việt Nam
chi phí vé máy bay cho chuyên gia nước ngoài
Good post but I was wondering if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Appreciate it! Car Accessories
ReplyDelete