Hybrid App混合开发程序员Android知识

Hybird App之选择器详解(一)

2018-01-01  本文已影响350人  Dwyane_Coding

学习混合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的特性,再加上自己的斜体

上一篇 下一篇

猜你喜欢

热点阅读