CSS 背景实例

CSS 实例

  • CSS 背景实例
  • CSS 文本实例
  • CSS 字体(font)实例
  • CSS 边框(border)实例
  • CSS 外边距 (margin) 实例
  • CSS 内边距 (padding) 实例
  • CSS 列表实例
  • CSS 表格实例
  • 轮廓(Outline) 实例
  • CSS 尺寸 (Dimension) 实例
  • CSS 分类 (Classification) 实例
  • CSS 定位 (Positioning) 实例
  • CSS 伪类 (Pseudo-classes)实例
  • CSS 伪元素 (Pseudo-elements)实例

01-设置背景颜色

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>01设置背景颜色</title>
<style type="text/css">
body {background-color: #009e8e;}
h1 {background-color: #ccf600;}
h2 {background-color: transparent;}
p {background-color: #ffae00;}
p.no2 {background-color: #afd400; padding: 20px;}
</style>
</head>
<body>
<h1>我是标题1</h1>
<h2>我是标题2</h2>
<p>我是段落</p>
<p class="no2">我设置了内边距。</p>
</body>
</html>


02设置文本的背景颜色

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>02设置文本的背景颜色</title>
<style type="text/css">
body {
background-color: #DDF0ED;
}
span.highlight {
background-color: #C7FFEC;
}
</style>
</head>
<body>
<p>
<span class="highlight">你说你想在海边买一所房子。</span>你说你想在海边买一所房子。 你说你想在海边买一所房子。你说你想在海边买一所房子。 你说你想在海边买一所房子。你说你想在海边买一所房子。 你说你想在海边买一所房子。你说你想在海边买一所房子。 你说你想在海边买一所房子。
<span class="highlight">你说你想在海边买一所房子。</span>
</p>
</body>
</html>


03将图像设置为背景

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>03将图像设置为背景</title>
<style>
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201511/846157-20151129175534453-599329583.jpg);
background-repeat: no-repeat;
}
p {
background-color: #E8DEAB;
}
</style>
</head>
<body>
<p>将图像设置为背景</p>
</body>
</html>


04如何重复背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>04如何重复背景图像</title>
<style>
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201511/846157-20151129183826047-1087351247.jpg);
background-repeat: repeat;
}
p {
background-color: #C7FFEC;
}
</style>
</head>
<body>
<p>如何重复背景图像</p>
</body>
</html>


05如何在垂直方向重复背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>05如何在垂直方向重复背景图像</title>
<style>
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201511/846157-20151129190113985-22881767.png);
background-repeat: repeat-y;
}
p {
background-color: #C7FFEC;
}
</style>
</head>
<body>
<p>如何在垂直方向重复背景图像</p>
</body>
</html>


06如何在水平方向重复背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>06如何在水平方向重复背景图像</title>
<style>
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201511/846157-20151129190113985-22881767.png);
background-repeat: repeat-x;
}
p {
background-color: #C7FFEC;
}
</style>
</head>
<body>
<p>如何在水平方向重复背景图像</p>
</body>
</html>


07如何仅显示一次背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>07如何仅显示一次背景图像</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151203170936299-1397498783.jpg);
background-repeat: no-repeat;
}
</style>
</head>
<body>
<p>如何仅显示一次背景图像</p>
</body>
</html>


08如何放置背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>08如何放置背景图像</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151203221303643-1294680219.png);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
</style>
</head>
<body>
<p><b>提示:</b>您需要把 background-attachment 属性设置为 "fixed",
才能保证该属性在 Firefox 和 Opera 中正常工作。
</p>
</body>
</html>


09如何使用%来定位背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>09如何使用%来定位背景图像</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151203223328455-392590785.png);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 30% 20%;
}
</style>
</head>
<body>
<p><b>注释:</b>为了在 Mozilla 中实现此效果,
background-attachment 属性必须设置为 "fixed"。
</p>
</body>
</html>


10如何使用像素来定位背景图像

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>10如何使用像素来定位背景图像</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151204104330361-341448993.png);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 200px 50px;
}
</style>
</head>
<body>
<p><b>注释:</b>为了在 Mozilla 中实现此效果,
background-attachment 属性必须设置为 "fixed"。
</p>
</body>
</html>


11如何设置固定的背景图像


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>11如何设置固定的背景图像</title>
<style type="text/css">
body {
background-image: url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151204105729486-1236967824.jpg);
background-repeat: no-repeat; }
</style>
</head>
<body>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
<p>图像不会随页面的其余部分滚动。</p>
</body>
</html>


12所有背景属性在一个声明之中

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>12所有背景属性在一个声明之中</title>
<style type="text/css">
body {
background: #C7FFEC url(http://images2015.cnblogs.com/blog/846157/201512/846157-20151204114642596-26790260.jpg) no-repeat fixed center;
}
</style>
</head>
<body>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
<p>这是一些文本。</p>
</body>
</html>


CSS背景实例总结:


W3School-CSS 背景实例的更多相关文章

  1. CSS 背景实例

    CSS 背景属性属性 描述background 简写属性,作用是将背景属性设置在一个声明中.background-attachment 背景图像是否固定或者随着页面的其余部分滚动.background ...

  2. html5--6-41 CSS背景

    html5--6-41 CSS背景 实例 学习要点 掌握CSS背景属性的使用 元素的背景属性: background 简写属性,作用是将背景属性设置在一个声明中. background-attachm ...

  3. CSS 背景background实例

    css背景background用于设置html标签元素的背景颜色.背景图片已经其他背景属性.本文章向码农介绍CSS 背景background使用方法和基本的使用实例.需要的码农可以参考一下. 一.Cs ...

  4. CSS 背景-CSS background

    这里有个很好的样式学习网站:http://www.divcss5.com/rumen/r125.shtml 一.Css background背景语法   -   TOP CSS背景基础知识 CSS 背 ...

  5. CSS 背景

    CSS 背景属性用于定义HTML元素的背景. CSS 属性定义背影效果: background-color background-image background-repeat background- ...

  6. HTML 背景实例

    71.HTML 背景实例好的背景使站点看上去特别棒.背景(Backgrounds)<body> 拥有两个配置背景的标签.背景可以是颜色或者图像.<body> 标签中的背景颜色( ...

  7. css sprite实例

    css sprite直译过来就是CSS精灵.通常被解释为“CSS图像拼合”或“CSS贴图定位”.本文章向码农们介绍css sprite使用方法和基本使用实例,需要的码农可以参考一下. 一.什么是css ...

  8. CSS背景和CSS3背景background属性

    css背景属性用于定义HTML元素的背景 背景属性既可以为单个的单元设置背景,也可以为整个页面设置背景,可以对上述二者的任意组合设置背景,段落.文字.不同状态的链接.图像.内容区域修改其背景样式.设置 ...

  9. CSS:CSS 背景

    ylbtech-CSS:CSS 背景 1.返回顶部 1. CSS 背景 CSS 背景属性用于定义HTML元素的背景. CSS 属性定义背景效果: background-color background ...

随机推荐

  1. Python中的编码

    http://liguangming.com/how-to-use-utf-8-with-python http://www.lijiejie.com/python-sys-setdefaultenc ...

  2. java.lang.IllegalStateException: Failed to read Class-Path attribute from manifest of jar file:/XXX

    出现这个问题的解决方案就是将原有的jar删除  然后重新下载过一遍就可以使用了  我估计是元数据等损坏了

  3. 第 19 章 CSS 其他样式

    学习要点: 1.颜色和透明度 2.盒子阴影和轮廓 3.光标样式 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 其他剩下几个常用的样式,包括颜色.透明度.盒子的阴影轮廓以及光标的样式. 一.颜 ...

  4. spring的使用《一》

    在前边的文章中说明了,如何搭建一个spring的开发环境,简单回顾下就是把spring的jar包导入工程中,如果是在javaWeb项目中是放在lib目录下,然后在web.xml文件中进行配置,配置sp ...

  5. Java的自动递增和递减

    和C 类似,Java 提供了丰富的快捷运算方式.这些快捷运算可使代码更清爽,更易录入,也更易读者辨读.两种很不错的快捷运算方式是递增和递减运算符(常称作"自动递增"和"自 ...

  6. Atitit.事件机制 与 消息机制的联系与区别

    Atitit.事件机制 与 消息机制的联系与区别 1. 消息/事件机制是几乎所有开发语言都有的机制,在某些语言称之为消息(Event),有些地方称之为(Message).1 2. 发布/订阅模式1 3 ...

  7. Test your application

    Creating automatic test suites for your application is a good way to make it robust. It allows you t ...

  8. [转]精通JS正则表达式

    原文路径:http://www.jb51.net/article/25313.htm 正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式 ...

  9. 【Spring】Spring框架之Struts2和Spring的优点

    Java Web开发使用Structs2和Spring框架的好处 今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术 ...

  10. Session Storage、Cache Storage

    Session Storage sessionStorage用于本地存储一个会话(session)的数据,这些数据只有在同一个会话中的页面才能访问并且当会话结束后数据也随之销毁(浏览器关闭).因此se ...