css基本语法

css在html中的用法:
第一种

<div style=" border: 1px solid red; color: red">div标签1</div>

在标签体内使用style属性。
第二种

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        div{
            border: 1px solid red;
        }
        span{
            border: 1px solid red;
        }
    </style>
</head>

在head标签体内添加css代码。
第三种

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="1.css">
</head>

创建css文件,在head里面引用文件。
css选择器:

标签选择器
<style>
    div{
        border: 1px solid yellow;
        color: blue;
        font-size: 30px;
    }
    span{
        border: 5px dashed blue;
        color: antiquewhite;
    }
</style>
id选择器

#id{	
	属性:值;
}

<style type="text/css">
    #id001{
        color: blue;
        font-size: 30px;
        border: yellow solid 1px;
    }
    #id002{
        color:  red;
        font-size: 20px;
        border: 5px dotted blue;
    }
</style>
class选择器
.class{
属性:值;
}

 class类型选择器,可以通过class属性有效的选择性的使用这个样式
 
 <style type="text/css">
   .div01{
       border: 1px solid red;
   }
</style>
组合选择器

选择器,选择器{
	属性:值
}

<style type="text/css">
   .div01,#div02{
       border: 1px solid red;
   }
</style>

常用样式:

<style type="text/css">
    div{
        color: red;  字体颜色
        border: 1px solid yellow; 边框大小 颜色 样式
        background-color: green; 背景
        width: 300px; 宽度
        height: 300px; 高度
        font-size: 20px; 字体大小
        margin: auto; 模块居中
        text-align: center; 字体居中
    }
    a{
        text-decoration: none; 超链接去下划线
    }
    table{
    border: red solid 1px;
    border-collapse: collapse; 去掉边框间距
}
ul{
    list-style: none; 去掉前缀
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值