侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

css教程:css指令,兼容,注释,selector

前端  /  管理员 发布于 7年前   174

1.2 跟css有关的标记,指令1.2.1 link<link rel="stylesheet" type="text/css" href="sheet1.css" media="all" />link标记的用意是允许将html与其他文档相关联。Css用link将css文档与html文档想关联。Css文档虽然不是html的一部分,但是被html使用,从外部style sheets引入它。Link在head元素内,但是不能放在任意head子元素的内部,比如title。Css文档的后缀名虽然不要求,但是有些浏览器不能识别非“.css”的文件。Link的属性: rel:代表relation,设为stylesheet。 type:描述数据的类型,设为text/css,告诉浏览器style sheet是css格式的。以后还会有其他的style sheet,比如xsl。 href:style sheet的url。 Media:指定style sheet的使用范围。下列大多数值还不被任何浏览器支持,常用的是all,print,screen。Opera支持projection。可以为media指定多个值,比如media="screen, projection"all Use in all presentational media.aural Use in speech synthesizers, screen readers, and other audio renderings of the document.braille Use when rendering the document with a Braille device.embossed Use when printing with a Braille printing device.handheld Use on handheld devices like personal digital assistants or web-enabled cell phones.print Use when printing the document for sighted users and also when displaying a "print preview" of the document.projection Use in a projection medium, such as a digital projector used to present a slideshow when delivering a speech.screen Use when presenting the document in a screen medium like a desktop computer monitor. All web browsers running on such systems are screen-medium user agents.tty Use when delivering the document in a fixed-pitch environment like teletype printers.tv Use when the document is being presented on a television. Title:利用title定义多个css文档相互替换的关系。 比如存在如下定义: <link rel="stylesheet" type="text/css" href="sheet1.css" title="Default" /><link rel="alternate stylesheet" type="text/css" href="bigtext.css" title="Big Text" /><link rel="alternate stylesheet" type="text/css" href="zany.css" title="Crazy colors!" />那么能同时支持多个css定义的浏览器中会有如下表现: 还可以通过将title设定为相同的value来分组:
<link rel="stylesheet" type="text/css"
href="sheet1.css" title="Default" media="screen" />
<link rel="stylesheet" type="text/css"
href="print-sheet1.css" title="Default" media="print" />
<link rel="alternate stylesheet" type="text/css"
href="bigtext.css" title="Big Text" media="screen" />
<link rel="alternate stylesheet" type="text/css"
href="print-bigtext.css" title="Big Text" media="print" />
上面的表述意为:css被title分为两组,default和Big Text。又每一组又被分为print和screen。如果有多个link元素,那么只有rel等于stylesheet的link可用。如果可用的link有多个,就会将它们同时作用于html文档,如下:<link rel="stylesheet" type="text/css" href="basic.css" /><link rel="stylesheet" type="text/css" href="splash.css" />1.2.2 stylestyle是引入style sheet最通用的方式。<style type="text/css">type:style总是使用type属性,当使用css时,type的值是“text/css”。Media:与link中一样。style以<style type="text/css">开头,以</style>结束,中间是多个styles。这些styles或者指向style sheet文档,或者以内嵌的方式表达。Style元素可以包含多个styles,也可以通过@import指令引入多个指向外部style sheet的链接。1.2.3 @import指令用法:
<style type="text/css">@import url(styles.css); /* @import comes first */@import url(blueworld.css);@import url(zany.css);h1 {color: gray;}</style>可见其作用类似link,l 通知浏览器将外部style sheet载入。l 并且可以载入多个style sheet。区别是l 位置与语法不同。@import被包含在style元素中,并且必须在其他css规则之前。l 每一个import的style sheet都会被使用,没有替代规则。相对于link的media属性,import有:@import url(sheet2.css) all;@import url(blueworld.css) screen;@import url(zany.css) projection, print;@import的重要用途:在导入的某个style sheet A中,A需要也使用外部的style sheet,这时link元素显然无用。比如css文档中,是不可能出现link元素的,这时使用@import,如下:@import url(http://example.org/library/layout.css);@import url(basic-text.css);@import url(printer.css) print;body {color: red;}h1 {color: blue;}1.3 与老版本浏览器的兼容问题浏览器对不能识别的tag一律忽略。但是如果浏览器不能识别style元素,style会以普通文本的形式出现在网页的最上面。解决方案:在style里面加上注释符号,这样旧版本的浏览器不会以文本方式显示,新版本浏览器可以正确使用style元素。具体如下:<style type="text/css"><!--@import url(sheet2.css);h1 {color: maroon;}body {background: yellow;}--></style>1.4 css中的注释css的注释类似c:/* This is a CSS1 comment */Comments can span multiple lines, just as in C :/* This is a CSS1 comment, and itcan be several lines long withoutany problem whatsoever. */但是注意:css的注释不能被嵌套。1.5内联风格inline style将style放到html元素描述的地方,就是inline style<p style="color: gray;">The most wonderful of all breakfast foods is the waffle--a ridged and cratered slab of home-cooked, fluffy goodness...</p>这个style属性是一个新属性,可以用到出现body元素中的所有元素上。可以看到style的值是一个字符串,使用和css一样的语法。但是这个字符串只能是一个风格声明块declaration block。不能将@import和css规则放到这个字符串中。就是说只能放css文档中出现在花括号中的文本。注意:inline style不被推荐使用,在xhtml1.1中inline style是反对的deprecated。因为,它显示违背数据和显示分离的原则。这个原则也是使用css的原因。2 selectorcss核心的特点是将规则应用到元素集上的能力。Css2规范种关于selector的部分,http://www.w3.org/TR/REC-CSS2/selector.html css的模式匹配pattern matching规则(css规范,地址如上):PatternMeaningDescribed in section *Matches any element.Universal selector EMatches any E element (i.e., an element of type E).Type selectors E FMatches any F element that is a descendant of an E element.Descendant selectors E > FMatches any F element that is a child of an element E.Child selectors E:first-childMatches element E when E is the first child of its parent. The :first-child pseudo-class E:link
E:visited
Matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited). The link pseudo-classes E:active
E:hover
E:focus
Matches E during certain user actions. The dynamic pseudo-classes E:lang(c) Matches element of type E if it is in (human) language c (the document language specifies how language is determined). The :lang() pseudo-class E FMatches any F element immediately preceded by an element E.Adjacent selectors E[foo]Matches any E element with the "foo" attribute set (whatever the value). Attribute selectors E[foo="warning"]Matches any E element whose "foo" attribute value is exactly equal to "warning". Attribute selectors E[foo~="warning"]Matches any E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "warning". Attribute selectors E[lang|="en"]Matches any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en". Attribute selectors DIV.warningHTML only. The same as DIV[class~="warning"]. Class selectors E#myidMatches any E element ID equal to "myid".ID selectors


  • 上一条:
    css教程:css和document
    下一条:
    CSS规则的结构和Grouping、class和id
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 使用 Alpine.js 排序插件对元素进行排序(0个评论)
    • 在js中使用jszip + file-saver实现批量下载OSS文件功能示例(0个评论)
    • 在vue中实现父页面按钮显示子组件中的el-dialog效果(0个评论)
    • 使用mock-server实现模拟接口对接流程步骤(0个评论)
    • vue项目打包程序实现把项目打包成一个exe可执行程序(0个评论)
    • 近期文章
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-03
    • 2018-04
    • 2018-05
    • 2018-06
    • 2018-09
    • 2018-11
    • 2018-12
    • 2019-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-04
    • 2021-05
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客