2.CSS基础-选择器

<span style="font-size:18px;">
</span>

1.派生选择器

     通过依据元素在其位置的上下文关系来定义样式

代码如下:

样式表里

li strong{
color:green;
}

html里代码

<body>
<p><strong>hello</strong></p>
<ul><li><strong>world</strong></li></ul>
</body>

运行结果:






2.id选择器

    id选择器可以为标有Id的HTML元素指定特定的样式

    id选择器以“#”来定义

   可以用作派生类选择器

代码如下:

样式表里


   #pid{
color: blue;
    }

html里

<body>
<p id=pid>you are beautiful!</p>
</body>

运行结果:

you are beautiful!


3.类选择器

   类选择器以一个点显示

  class也可以用作派生类选择器

代码如下:

样式表里

    .pclass{
color: red;
}

html里

<body>
<p class="pclass">you are beautiful!</p>
</body>

运行结果:

you are beautiful!

4.属性选择器

  对带有指定属性的HTML元素设置样式

代码如下:指定属性title

   <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
    [title]{
      color:blue;
    }
</style>
</head>
<body>
<p title='i'>属性选择器/p>
</body>
</html>


属性和值选择器:如果属性指定具体的值则必须按照指定具体的值来写

代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
    [title]{
      color:blue;
    }
    [title=a]{
    color: red}
</style>
</head>
<body>
<p title='i'>属性选择器</p>
<p title="a">属性和值选择器</p>
</body>
</html>

运行结果:

属性选择器

属性和值选择器



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值