您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

CSS的后代选择器基础使用示例详解

2024/2/19 23:41:37发布24次查看
基础
来看一个后代选择器的最简单写法,strong标签属于p标签的后代,i标签属于strong标签后代:
html代码:
<p> my name is <strong>li<i>daze</i></strong>, hahah. </p>
css代码:
p strong { font-size: 30px; } p i { font-size: 40px; }
1、在后代选择器中,规则左边的选择器一端包括两个或多个用空格分隔的选择器。
2、选择器之间的空格是一种结合符。
3、后代选择器,后代的层次间隔可以是无限的,注意与子元素选择器的区别。
示例1
<html> <head> <style type="text/css"> ul em {color:red; font-weight:bold;} </style> </head> <body> <ul> <li>list item 1 <ol> <li>list item 1-1</li> <li>list item 1-2</li> <li>list item 1-3 <ol> <li>list item 1-3-1</li> <li>list item <em>1-3-2</em></li> <li>list item 1-3-3</li> </ol> </li> <li>list item 1-4</li> </ol> </li> <li>list item 2</li> <li>list item 3</li> </ul> </body> </html>
执行效果:
示例2
<html> <head> <style type="text/css"> p.sidebar {width:100px;height:100px;background:blue;} p.maincontent {width:100px;height:100px;background:yellow;} p.sidebar a:link {color:white;} p.maincontent a:link {color:red;} </style> </head> <body> <p class='sidebar'> <a href ='#'>我是链接1<a/> </p> <p class='maincontent'> <a href ='#'>我是链接1<a/> </p> </body> </html>
执行效果
一点说明:
xml/html code复制内容到剪贴板
a:link {color: #ff0000}         /* 未访问的链接 */
a:visited {color: #00ff00}  /* 已访问的链接 */
a:hover {color: #ff00ff}    /* 鼠标移动到链接上 */
a:active {color: #0000ff}   /* 选定的链接 */
更多css的后代选择器基础使用示例详解。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product