Hybird-App之选择器详解(一)

学习混合app开发,要学会一些基础才能上手。本文主要介绍元素选择器、选择器分组、类选择器

元素选择器

最常见的选择器就是元素选择器,文档的元素就是最基本的选择器
例如:h1{} a{}
index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选择器</title>
    <link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
    <p>Hello Dwyane!</p>
</body>
</html>

style.css

p{
    color: green;
}
选择器分组
<body>
    <h1>标题1</h1>
    <h2>标题2</h2>
</body>

style.css

h1, h2{
    color: green;
}

结果:
image.png

另外还有个通配符*,通常在通配符设置marigin值、padding值

*{
    margin: 0px;
    padding: 0px;
}
类选择器

1、类选择器允许以一种独立于文档元素的方式来指定样式
例如:.class{}
index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选择器</title>
    <link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
    <div class="div">hello,Dwyane</div>
</body>
</html>

style.css

.div{
    color: blue;
}

结果:
image.png

2、结合元素选择器:例如:a.class{}
index.html

<body>
    <div class="div">hello,Dwyane</div>
    <a class="div">hello,Dwyane</a>
</body>

style.css

a.div{
    color: blue;
}

只指定a标签的div更改,所以未指定的div不会更改
结果:
image.png

3、多类选择器
index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选择器</title>
    <link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
    <p class="p1">this is my web page</p>
    <p class="p2">this is my web page</p>
    <p class="p3">this is my web page</p>
</body>
</html>

style.css

.p1{
    color: blue; //p1更改颜色
}
.p2{
    font-size: 30px; //p2更改字号
}
.p3{
    font-style: italic; //p3斜体
}

结果:
image.png

运用多类选择器,我们可以
index.html

<body>
    <p class="p1">this is my web page</p>
    <p class="p2">this is my web page</p>
    <p class="p1 p2">this is my web page</p> //p1 p2中间用空格隔开,这样继承了前两个class的特性
</body>

style.css

.p1{
    color: blue; //p1更改颜色
}
.p2{
    font-size: 30px; //p2更改字号
}
.p1.p2{
    font-style: italic; //p1 p2斜体
}

结果:
结果:
image.png

.p1.p2继承了p1和p2的特性,再加上自己的斜体

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值