Wednesday, December 1, 2021
One of the first thing you would do in web development is to link an external Cascading Stylesheet to an HTML document. As a matter of fact bootstrap would not work if you didn't link the bootstrap.css file in your HTML document. Linking an external document is easy enough you often see the link like this
Now let's break it down link attributes, there are four possible attributes for the link tag.
They are the following:
Another way you can link to an external stylesheet is with the @import directive, which you don't see very often. It is used a little differently. You have to put it on the first line or before the CSS rules inside the <style> tag like so
The cool thing about the @import directive is that you can have one stylesheet imported in another. To demonstrate this let's create two stylesheets and have one stylesheet import the other.
First create the nav.css file with the following markup
Now create the styles.css file with the following markup
The next step is to create an index.html file to import the styles.css file. Even though you only imported the styles.css file with the @import directive, you also have access to the nav.css style rules because the styles.css file already imported the nav.css file.
The html markup looks like the following:
The output of the HTML file should look like this
Previous: Bootstrap 4: Grid System Cheat Sheet
Next: Target Specific Media Environments With CSS Media And Feature Queries
<link href="Content/bootstrap.css" media="all" rel="stylesheet" type="text/css"></link> <script src="Scripts/bootstrap.js"></script>
Now let's break it down link attributes, there are four possible attributes for the link tag.
They are the following:
- rel (required) - Relations, relationship to this page. For CSS stylesheets its "stylesheet"
- type (optional) - is the type of the link, "text/css" is the type for CSS stylesheets
- href (required) - is the location of the resource, it could a relative path or an actual URL like a CDN
- media (optional) - with this attribute you can specify which media the stylesheet is meant for. For example the media attribute can have the "projector" value.
Another way you can link to an external stylesheet is with the @import directive, which you don't see very often. It is used a little differently. You have to put it on the first line or before the CSS rules inside the <style> tag like so
<style> @import url(CSS/styles.css); </style>
The cool thing about the @import directive is that you can have one stylesheet imported in another. To demonstrate this let's create two stylesheets and have one stylesheet import the other.
First create the nav.css file with the following markup
.nav-really-small-font{ font-size: 5px; }
Now create the styles.css file with the following markup
@import(nav.css); body { } .styles-really-big-fonts{ font-size: 50px; }
The next step is to create an index.html file to import the styles.css file. Even though you only imported the styles.css file with the @import directive, you also have access to the nav.css style rules because the styles.css file already imported the nav.css file.
The html markup looks like the following:
<!DOCTYPE html> <html> <head> <link href="Content/bootstrap.css" type="text/css" rel="stylesheet" media="all" /> <link href="Content/bootstrap.css" rel="stylesheet" /> <script src="Scripts/bootstrap.js"></script> <meta charset="utf-8" /> <title></title> <style> @import url(CSS/styles.css); </style> </head> <body> <p class="styles-really-big-fonts">This is from styles stylesheet</p> <p class="nav-really-small-font">This is from nav stylesheet</p> </body> </html>
The output of the HTML file should look like this
Previous: Bootstrap 4: Grid System Cheat Sheet
Next: Target Specific Media Environments With CSS Media And Feature Queries
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
This comment has been removed by the author.
ReplyDeleteNice article!! A very well written and well-structured article. It was really an informative article.
ReplyDeleteWordPress Design Agency
CSS link to stylesheet is the important. I am working with the cheap assignment writing service to the students those want to working from the other sources.
ReplyDeleteOne of the first thing you would do in web development is to link an external Cascading Stylesheet to an HTML document
ReplyDelete