【web前端】CSS样式

CSS应用方式

在标签

<h2 style="color: aquamarine">hello world!</h2>

在head标签中写style标签

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            height: 100px;
        }
        .c2{
            height: 200px;
            color: aqua;
        }
    </style>
</head>
<body>

<h1 class="c1">用户列表</h1>

<h1 class="c2">用户列表</h1>

</body>

写到文件

  • 文件:
.c1{
    height: 100px;
}
.c2{
    height: 200px;
    color: aqua;
}
  • html:
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="com.css">

</head>
<body>

<h1 class="c1">用户列表</h1>

<h1 class="c2">用户列表</h1>

选择器

类选择器

.c1{
    color: pink;
}
<h1 class="c1">乒乓球</h1>

ID选择器

#c2{
    height: 100px;
}
<h2 ID="c2">羽毛球</h2>

标签选择器

li{
    color: aquamarine;
}
<ul>
    <li>篮球</li>
    <li>排球球</li>
</ul>

属性选择器

input[type='text']{
    border: 1px;
    color: chocolate;
}
<input type="text">
<input type="password">

后代选择器

.yy li{
    color: blue;
}
<div class="yy">
    <ul>
        <li>中国</li>
        <li>美食</li>
    </ul>
</div>

多个样式和覆盖

覆盖顺序是按照style中的顺序来的, <div class="c2 c1">中国移动</div>和 <div class="c1 c2">中国移动</div>是一样的效果

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            color: blue;
            border: 1px solid red;
        }
        .c2{
            font-size: 20px;
            color: aqua;
        }
    </style>
</head>
<body>
    <div class="c1 c2">中国移动</div>
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值