• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

HTML和CSS3background属性的使用方法

武飞扬头像
伟大的程序坤
帮助1

我在第一次上超文本标记语言课的时候接触到的第一个属性就是backgroud(背景图像),当时的写法是直接在body标签后面直接连接图片地址 就像下面这样,不知道有多少人和我一样刚开始是这样写的。现在都在css里面写了,这种方法基本不用了。因为css可以更好的控制布局。

  1.  
    <!doctype html>
  2.  
    <html>
  3.  
    <head>
  4.  
    <meta charset="utf-8">
  5.  
    <title>a</title>
  6.  
    </head>
  7.  
     
  8.  
    <body background="a.jpg"> <!--插入背景图片-->
  9.  
    </body>
  10.  
    </html>

在CSS3中增强了background属性。下面的表格是background在css3中的常用子属性。

background-image 背景图像
background-color 背景颜色
background-origin 指定背景的显示区域
background-clip 背景的剪裁区域
background-repeat 设置背景图像是否及如何重复铺排
background-size 指定背景图像大小
background-position 设置背景图像位置
background-attachment 定义背景图像的显示方式

 background-image的使用方法:

  1.  
    <!doctype html>
  2.  
    <html>
  3.  
    <head>
  4.  
    <meta charset="utf-8">
  5.  
    <title>a</title>
  6.  
    <style type="text/css">
  7.  
    body{
  8.  
    background-image:url("a.jpg") ; <!--定义背景图像-->
  9.  
    }
  10.  
     
  11.  
     
  12.  
    </style>
  13.  
    </head>
  14.  
     
  15.  
    <body>
  16.  
    </body>
  17.  
    </html>
学新通

background-color。也可以在body标签里使用bgcolor来设置背景颜色,早期学习的时候我学的就是bgcolor,但是现在好像也没多少人这样用了。

  1.  
    <!doctype html>
  2.  
    <html>
  3.  
    <head>
  4.  
    <meta charset="utf-8">
  5.  
    <title>a</title>
  6.  
    <style type="text/css">
  7.  
    body{
  8.  
    background-color: red; <!-- 背景颜色为红色 red也可以使用rgb来带替-->
  9.  
    }
  10.  
     
  11.  
     
  12.  
    </style>
  13.  
    </head>
  14.  
     
  15.  
    <body>
  16.  
    </body>
  17.  
    </html>
学新通

其它六个子属性也没啥好说的新手想学的可以自己动手去尝试,我在补充一下background-repeat

CSS3可以通过background-repeat属性来控制背景图像的显示方式,他有如下几个取值参数

repeat-x:背景图像在横向上平铺

repeat-y:背景图像在纵向上平铺

repeat:背景图像在横向和纵向平铺

no-repeat:背景图像不平铺

round:背景图像自动缩放调整以填充容器

space:以相同间距平铺填充整个容器

最后两个取值round和space好像只有CSS3才支持。

感兴趣的小伙伴可以自己动手尝试设置。

文章很简单只是写一写网页最基础的东西。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgefgee
系列文章
更多 icon
同类精品
更多 icon
继续加载