【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>

相关推荐

  1. WEB前端CSS常见样式以及各种简单样式

    2024-06-10 11:16:04       31 阅读
  2. 前端CSS样式(image)

    2024-06-10 11:16:04       17 阅读
  3. HTML:浏览器CSS样式前缀

    2024-06-10 11:16:04       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-10 11:16:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-10 11:16:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-10 11:16:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-10 11:16:04       18 阅读

热门阅读

  1. 列举常见的SQL语句

    2024-06-10 11:16:04       10 阅读
  2. 谈谈 Tomcat 连接器

    2024-06-10 11:16:04       7 阅读
  3. 2024年城市客运安全员考试题库及答案

    2024-06-10 11:16:04       9 阅读
  4. Redis 的一些关键知识点及示例

    2024-06-10 11:16:04       9 阅读
  5. React@16.x(24)自定义HOOK

    2024-06-10 11:16:04       10 阅读
  6. 近邻算法详解

    2024-06-10 11:16:04       9 阅读
  7. 5_1 Linux 计划任务

    2024-06-10 11:16:04       8 阅读