first-of-tye和first-child的区别

first-of-tye和first-child的区别

first-of-tye和first-child的的效果是一样的吗?我试了一下,浏览器显示的效果一样

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

是first-of-type吧,少了个字母。

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>first-of-type and first-child</title>
<style type="text/css">
div:first-child{
    color: #f00;
}
p:first-of-type{
    color: #0f0;
}
</style>
</head>
<body>
<div>
    <div>第一个div中第一个元素</div>
    <p>第一个div中的第一个p,但不是第一个元素</p>
</div>

<hr>

<div>
    <p>第二个div中的第一个p,也是第一个元素</p>
    <div>第二个div中第二个元素</div>
</div>
</body>
</html>

效果图:

http://img1.sycdn.imooc.com/climg//591ec9c000010df603940195.jpg

应该知道区别了吧

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师