CSS的使用

文章目录

    • CSS使用方式
    • CSS字体样式属性
    • CSS外观属性

一、CSS使用方式

1. 行内样式

<!DOCTYPE html>
<html lang="en">
   <head>
       <title>This is title</title>
   </head>
   <body>
       <p style="font-size: 16px; color: red;">大家好</p>    </body>
</html>

2 .内部样式表

<!DOCTYPE html>
<html lang="en">
   <head>
       <title>This is title</title>
       <style>
           p {
               font-size: 16px;           

               color: red;
              }
       </style>
   </head>
   <body>
       <p>Hello everyone</p>    </body>
</html>

3 .外部样式表
链接式
将样式写到单独的文件中,文件的扩展名为 .css 。例如, index.css 文件中有如下样式:

p{
   font-size: 16px;    color: red;
}
然后通过   <link> 元素将   index.css 文件引入到页面中:
<!DOCTYPE html>
<html lang="en">
   <head>
       <title>This is title</title>
       <link rel="stylesheet" type="text/css" href="./css/index.css">    </head>
   <body>
       <p>我是优秀的开发工程师</p>    </body>
</html>

4.css使用方式总结
  (1)定义在外部文件(外链样式):开发中主要是通过这种形式定义样式。

  (2)在页面的头部定义(内联样式):通过这种形式定义的样式只在本页面内生效。

(3)定义在特定的元素身上(行内样式):这种形式多用于测试,可维护性较差。

 二、CSS字体样式属性

font-size:字号大小

font-family:字体

font-weight:字体粗细

font-style:字体风格

三、CSS外观属性

1. color:文本颜色

属性值:预定义的颜色名  | 十六进制值的颜色值  | RGB颜色值

2 .颜色半透明(css3)

color: rgba(r,g,b,a) a 是alpha , 透明的意思        

取值范围 : 0~1之间      

color: rgba(0,0,0,0.3)

3 .line-height:行间距

  • normal:默认值,行高由浏览器自动处理。
  • 数字:行高 = 数字 * 字体大小,例如, line-height: 2;font-size: 16px; ,则行高等于:2 * 16px = 32px
  • 长度值:使用长度值设置行高,例如, line-height: 32px 。
  • 百分比:基于当前字体大小的百分比。

4. text-align:水平对齐方式

属性值:left | right | center | justify

5. text-indent:首行缩进

6. text-decoration:文本修饰

7. text-transform:大小写转换

8 .letter-spacing:字符间距

9 .word-spacing(单词)

10. 文字阴影

text-shadow:水平位置    垂直位置    模糊距离    阴影颜色;


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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值