CSS Powerpoint 2024 112324
CSS Powerpoint 2024 112324
External stylesheet
An external stylesheet contains CSS in a separate file with a .css extension. This is the most
common and useful method of bringing CSS to a document. You can link a single CSS file to
multiple web pages, styling all of them with the same CSS stylesheet.
You reference an external CSS stylesheet from an HTML <link> element:
TRY it:::
To link an external stylesheet, you'd include a <link> element inside your <head>:
• There are
.
a number of other common types you'll come across. For
example, a link to the site's favicon:
There are a number of other icon rel values, mainly used to indicate special icon types for
use on various mobile platforms, e.g.:
The size attribute indicates the icon size, while the type contains the MIME type of the resource being
linked. These provide useful hints to allow the browser to choose the most appropriate icon available.
.
You can also provide a media type or query inside a media attribute;
this resource will then only be loaded if the media condition is true.
For example:
.
Some interesting new performance and security features have been
added to the <link> element too. Take this example
A rel value of preload indicates that the browser should preload this resource
(see rel="preload" for more details), with the as attribute indicating the specific class of content being fetched.
The crossorigin attribute indicates whether the resource should be fetched with a CORS request.
CORS (Cross-Origin Resource Sharing) is a system, consisting of transmitting HTTP headers, that determines
whether browsers block frontend JavaScript code from accessing responses for cross-origin requests.
The same-origin security policy forbids cross-origin access to resources. But CORS gives web servers the ability to
say they want to opt into allowing cross-origin access to their resources.
CORS headers
Access-Control-Allow-Origin
Indicates whether the response can be shared.
Access-Control-Allow-Credentials
Indicates whether or not the response to the request can be exposed when the credentials flag is true.
Access-Control-Allow-Headers
Used in response to a preflight request to indicate which HTTP headers can be used when making the actual
request.
Access-Control-Allow-Headers
. Used in response to a preflight request to indicate which HTTP
headers can be used when making the actual request.
Access-Control-Allow-Methods
Specifies the method or methods allowed when accessing the
resource in response to a preflight request.
Access-Control-Expose-Headers
Indicates which headers can be exposed as part of the response
by listing their names.
Access-Control-Max-Age
Indicates how long the results of a preflight request can be
cached.
Access-Control-Request-Headers
. Used when issuing a preflight request to let the server know
which HTTP headers will be used when the actual request is
made.
Access-Control-Request-Method
Used when issuing a preflight request to let the server know
which HTTP method will be used when the actual request is
made.
Origin
Indicates where a fetch originates from.
Timing-Allow-Origin
Specifies origins that are allowed to see values of attributes
retrieved via features of the Resource Timing API, which would
otherwise be reported as zero due to cross-origin restrictions.
.
• Other usage notes:
• A <link> element can occur either in the <head> or <body> element, depending on whether it has a link
type that is body-ok. For example, the stylesheet link type is body-ok, and therefore <link
rel="stylesheet"> is permitted in the body. However, this isn't a good practice to follow; it makes more
sense to separate your <link> elements from your body content, putting them in the <head>.
• When using <link> to establish a favicon for a site, and your site uses a Content Security Policy (CSP) to
enhance its security, the policy applies to the favicon. If you encounter problems with the favicon not
loading, verify that the Content-Security-Policy header's img-src directive is not preventing access to it.
.