css body的背景颜色设置

一:使用标签类型定义样式

1.内部样式

body的背景颜色设置的一个代码样例


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset = "utf-8">
  5. <title> css背景 </title>
  6. </head>
  7. <style>
  8. body{
  9. background-color:green;
  10. }
  11. h1{
  12. color:orange;
  13. text-align:center;
  14. }
  15. </style>
  16. <body>
  17. <h1>css3 实例 </h1>
  18. </body>
  19. </html>

第二种写法

这个是内联样式,直接对标签操作


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset = "utf-8">
  5. <title> css背景 </title>
  6. </head>
  7. <body style="background-color:green">
  8. <h1 style="color:orange;text-align:center">css3 实例 </h1>
  9. </body>
  10. </html>
还可以放在外面,如同茴香豆的茴有好几种写法一样

第三种写法

放在外面,是外部样式,相当于第一种内部样式把<style></style>变成文件名称

编写style.css文件


 
 
  1. body{
  2. background-color:green;
  3. }
  4. h1{
  5. color:orange;
  6. text-align:center;
  7. }
编写index.html文件


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset = "utf-8">
  5. <title> css背景 </title>
  6. <link rel="stylesheet" type="text/css" href="style.css">
  7. </head>
  8. <body >
  9. <h1 >css3 实例 </h1>
  10. </body>
  11. </html>


二:使用标签id制定样式

使用#表示对id的样式,其实和内联样式一样,就是可能在style代码很多的时候放在外面增加可读性


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset = "utf-8">
  5. <title> css背景 </title>
  6. </head>
  7. <style>
  8. #e1{
  9. text-align:center;
  10. color:red;
  11. }
  12. </style>
  13. <body >
  14. <h1 id="e1">css3 实例 1 </h1>
  15. <h1 id="e2">css3 实例 2 </h1>
  16. </body>
  17. </html>

三:使用.class定义一般样式


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset = "utf-8">
  5. <title> css背景 </title>
  6. </head>
  7. <style>
  8. .classhh{
  9. text-align:center;
  10. color:red;
  11. }
  12. </style>
  13. <body >
  14. <h1 id="e1" class="classhh">css3 实例 1 </h1>
  15. <h1 id="e2">css3 实例 2 </h1>
  16. </body>
  17. </html>

总结:

1.指定样式类型有三种方式:

       1.根据标签类型指定:label_tyle{}

       2.根据标签名制指定:#id_name{}

       3.根据类名制定:.class_name{}

2.样式的存放有三个地方

       1.内联,直接放在<,style:"">

       2.内部,head中<style></style>

       3.外部,最常见


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Famiglistimott

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值