<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>selector-id.html</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <!-- ID 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。 ID 选择器以 "#" 来定义。ID 选择器中可以忽略通配选择器(*)。 类选择器和 ID 选择器可能是区分大小写的。这取决于文档的语言。HTML 和 XHTML 将类和 ID 值定义为区分大小写,所以类和 ID 值的大小写必须与文档中的相应值匹配。 在某些方面,ID 选择器类似于类选择器,不过也有一些重要差别。 类选择器和ID选择器: 区别 1:只能在文档中使用一次 在一个 HTML 文档中,ID 选择器会使用一次,而且仅一次。 区别 2:不能使用 ID 词列表 ID 选择器不能结合使用,因为 ID 属性不允许有以空格分隔的词列表。 区别 3:ID 能包含更多含义 有些情况下,您知道文档中会出现某个特定 ID 值,但是并不知道它会出现在哪个元素上,所以您想声明独立的 ID 选择器。 id 选择器和派生选择器:在现代布局中,id 选择器常常用于建立派生选择器。 --> <style type="text/css"> #intro { font-weight:bold; color:red; } #sidebar p { font-style: italic; text-align: right; margin-top: 0.5em; } </style> </head> <body> <p id="intro">This is a paragraph of introduction.</p> <p>This is a paragraph.</p> <p>This is a paragraph.</p> <div id="sidebar"><p>This is a paragraph.</p></div> <p>...</p> </body> </html>
css selector - id
猜你喜欢
转载自jaesonchen.iteye.com/blog/2287504
今日推荐
周排行