CSS Pocket Reference

#CSS Pocket Reference
##CHAPTER 1 Basic Concepts
###Adding Styles to HTML and XHTML
####Inline Styles
In HTML and XHTML, style information can be specified for an individual element via the style attribute. The value of a style attribute is a declaration block (see the section “Rule Structure” on page 5) without the curly braces:

<p style="color: red; background: yellow;">Look out!
This text is alarmingly presented!</p>  

XML languages may or may not provide an equivalent capability; always check the language DTD to be certain.
###Embedded Style Sheets A style sheet can be embedded at the top of an HTML or XHTML document using the style element, which must appear within the head element.XML languages may or may not provide an equivalent capability; always check the language DTD to be certain.
###External Style Sheets
Another key advantage is that external style sheets are cached, which can help reduce bandwidth usage. An external style sheet can be referenced in one of the following three ways:

  • @import directive

    <head><title>My Document</title> <style type="text/css"> @import url(site.css); @import url(navbar.css); @import url(footer.css); body {background: yellow;} </style> </head>

Note that @import directives can appear at the top (and, according to the specification, only at the top) of any style sheet. Thus, one style sheet could import another, which in turn would import a third.

  • link element

    <head> <title>A Document</title> <link rel="stylesheet" type="text/css" href="basic.css" media="all"> <link rel="stylesheet" type="text/css" href="web.css" media="screen"> <link rel="stylesheet" type="text/css" href="paper.css" media="print"> </head>

It is also possible to link to alternate style sheets. If alternate style sheets are supplied, it is up to the user agent (or the author) to provide a means for the user to select one of the alternates:

<head>
<title>A Document</title>
<link rel="stylesheet" type="text/css" href="basic.css">
<link rel="alternate stylesheet" title="Classic"
type="text/css" href="oldschool.css">
<link rel="alternate stylesheet" title="Futuristic"
type="text/css" href="3000ad.css">
</head>  

*xml-stylesheet processing instruction
In XML documents (such as XHTML documents sent with a mime-type of “text/xml,” “application/xml,” or “application/ xhtml+xml”), an xml-stylesheet processing instruction can be used to associate a style sheet with a document. Any xml-style sheet processing instructions must be placed in the prolog of an XML document. Multiple xml-stylesheet processing instructions are permitted. The media pseudo-attribute can be used to restrict a style sheet to one or more forms of media:

<?xml-stylesheet type="text/css" href="basic.css" media="all"?>

<?xml-stylesheet type="text/css" href="web.css" media="screen"?>

<?xml-stylesheet type="text/css" href="paper.css" media="print"?>

It is also possible to link to alternate style sheets with the xmlstylesheet processing instruction:

<?xml-stylesheet type="text/css" href="basic.css"?>

<?xml-stylesheet alternate="yes" title="Classic" type="text/css" href="oldschool.css"?>

<?xml-stylesheet alternate="yes" title="Futuristic" type="text/css" href="3000ad.css"?>

转载于:https://my.oschina.net/LosersAFC/blog/213251

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值