CSS【2】-- CLASSES AND IDS

7 篇文章 0 订阅
7 篇文章 0 订阅
  • Multiple Selectors
<div>
    <div>
        <p>I like tacos!</p>

So what if you want to grab

s that are inside two

s, and not all

s?

You select those in the CSS tab like this:

div div p {
    /*CSS stuff!*/
}
  • One selector to rule them all
 * {
 ...;
}
  • Parents, children, and siblings
<!DOCTYPE html>
<html> <!--The trunk of the tree!-->
    <head> <!--Child of html, parent of title,
           sibling of body-->
        <title></title> <!--Immediate child of head,
                        child of head AND html-->
    </head>
    <body> <!--Child of html, parent of p,
           sibling of head-->
        <p></p> <!--Immediate child of body,
                child of body AND html-->
    </body>
</html>
  • Swinging from branch to branch

    这里写图片描述

 you can reach an element that is a child of another element like this:

div div p { /* Some CSS */ }

If you want to grab direct children—that is, an element that is directly nested inside another element, with no elements in between—you can use the > symbol, like so:

div > p { /* Some CSS */ }
  • class and an ID
  • class – some selectors
  • id – one selector
Classes are useful when you have a bunch of elements that should all receive the same styling. 

<div class="square"></div>
<img class="square"/>
<td class="square"></td>

Classes are identified in CSS with a dot (.), like so:

.square {
    height: 100px;
    width: 100px;
}

这里写图片描述

这里写图片描述

IDs, on the other hand, are great for when you have exactly one element that should receive a certain kind of styling.

<div id="first"></div>
<div id="second"></div>
<p id="intro"></p>

#first {
    height: 50px;
}

#second {
    height: 100px;
}
  • pseudo-class selectors
is a way of accessing HTML items that aren't part of the document tree

selector:pseudo-class_selector {
    property: value;
}

这里写图片描述

文件【css2-text.html css2-text.css】

**pseudo-class selectors**

a:link: An unvisited link.
a:visited: A visited link.
a:hover: A link you're hovering your mouse over.
  1. Another useful pseudo-class selector is first-child.
p:first-child {
    color: red;
}

这里写图片描述

p:nth-child(2) {
    color: red;
}

:nth-child

这里写图片描述

一定要注意是body的第几个child,如果body下面是h3,p,p,p,如果写第三个p,也就是最后一个p的话,它其实是body的第四个child,h3是first-child

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值