CSS3入门之边框与背景

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

1、前言

CSS3作为CSS的最新版本,在展示效果上有非常大的提升,接下来,我们就一起领略一下CSS3的风采吧。

2、CSS3边框

2.1、border-radius(用于设置圆角边框)

在CSS2时代,要想实现圆角边框,是一件非常麻烦的事情。一种实现方式是使用一个背景图片,为了实现伸缩效果,还需要至少3张图片拼凑,相当麻烦。另外一种实现方式是使用多个div重叠来实现圆角。

在CSS3中,有一个非常简单的属性,那就是border-radius。

语法: border-radius: 1-4 length|% / 1-4 length|%;

border-radius: 10px;
//等价于
border-top-left-radius:10px;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
border-bottom-left-radius:10px;

<div style="border-radius:10px;">
演示圆角边框
</div>
演示圆角边框

兼容性说明: IE9+,Chrome,FF,Safari,Oprea

div
{
border:2px solid;
border-radius:25px;
-moz-border-radius:25px; /* Old Firefox */
}

2.2、box-shadow(用于添加边框阴影)

语法: box-shadow: h-shadow v-shadow blur spread color inset;,其中h-shadow和v-shadow是必须设置,允许负值。【参数说明:水平阴影的位置,垂直阴影的位置,模糊距离,阴影的尺寸,阴影的颜色,外部引用(outset)改为内部阴影】

<div style="border-radius:10px; border: 1px solid red;">
演示圆角边框
</div>
简单阴影
<div style="box-shadow: -2px -2px red;">
简单阴影
</div>
简单阴影
<div style="box-shadow: -2px -2px 10px red;">
带模糊效果的阴影
</div>
带模糊效果的阴影
<div style="box-shadow: 2px 2px 10px 10px red;">
带模糊效果指定尺寸的阴影
</div>
带模糊效果指定尺寸的阴影
<div style="box-shadow: 2px 2px 10px 10px red inset;">
内部阴影
</div>
内部阴影

兼容性说明: IE9+,Chrome,FF,Safari,Oprea

2.3、border-image(CSS3边框图片)

border-image是简写属性,全部是:

border-image-source  //背景图片源
border-image-slice //图片边框内偏移
border-image-width //图片边框的宽度
border-image-outset //边框图像区域超出边框的量
border-image-repeat //边框是否适应平铺(repeated)、铺满(rounded)、拉伸(stretched)

<div style="border-width:10px;border-image: url(http://www.w3school.com.cn/i/border.png) 10 10 round;">
简单图片边框
</div>
简单图片边框
<div style="border-width:10px;border-image: url(http://www.w3school.com.cn/i/border.png) 10 10 50 round">
完全设置的图片边框
</div>
完全设置的图片边框

兼容性说明: Chrome,FF,Safari,Oprea

div
{
border-image:url(border.png) 30 30 round;
-moz-border-image:url(border.png) 30 30 round; /* 老的 Firefox */
-webkit-border-image:url(border.png) 30 30 round; /* Safari 和 Chrome */
-o-border-image:url(border.png) 30 30 round; /* Opera */
}

3、CSS3背景

整体兼容性

以下CSS背景的特性,全部支持IE9+,FF,Chrome,Safari,Oprea

3.1、background-size(用于规定背景图片的尺寸)

在以前的CSS中,背景图片的大小,是由图片本身的大小决定的。在CSS3中,有一个简单的CSS样式可以设置背景图片的大小,允许我们在不同的环境中重复使用背景图片。可以以像素或百分比规定尺寸。

<div style="
background-image:url(http://www.w3school.com.cn/i/bg_flower_small.gif);
background-size: 50% 70%;
background-repeat:no-repeat;">
</div>
简单设置背景图大小

3.2、background-origin(规定背景图片的定位区域)

盒子模型示意图:

background-origin属性则可以设置背景图片放置于哪个区域上(content-box,padding-box,border-box)

<div style="width:66px;height:125px;
background-image:url(http://www.w3school.com.cn/i/bg_flower_small.gif);
background-origin:content-box;
padding: 20px;border:20px solid red;"></div>
 
<div style="width:66px;height:125px;
background-image:url(http://www.w3school.com.cn/i/bg_flower_small.gif);
background-origin:border-box;
padding: 20px;border:20px solid red;"></div>
 
<div style="width:66px;height:125px;
background-image:url(http://www.w3school.com.cn/i/bg_flower_small.gif);
background-origin:padding-box;
padding: 20px;border:20px solid red;"></div>
 

3.3、多重背景

可以针对标签设置多个背景,用法如下:

body
{
background-image:url(bg_flower.gif),url(bg_flower_2.gif);
}

CSS3入门之边框与背景的更多相关文章

  1. CSS3常用属性(边框、背景、文本效果、2D转换、3D转换、过渡、有过渡效果大图轮播、动画)

    CSS3边框: 1.CSS3圆角:border-radius  属性--创建边框线的圆角 <body style="font-size:24px; color:#60F;"& ...

  2. 第95天:CSS3 边框、背景和文字效果

    1.CSS3边框: border-radius:CSS3圆角边框.在 CSS2 中添加圆角矩形需要技巧,我们必须为每个圆角使用不同的图片,在 CSS3 中,创建圆角是非常容易的,在 CSS3 中,bo ...

  3. CSS3 边框 圆角 背景

    CSS3用于控制网页的样式布局. CSS3是最新的CSS标准.   关于transform: transform:rotate(10deg);//顺时针方向旋转10° 浏览器支持情况:低版本的IE浏览 ...

  4. css3 边框、背景、文本效果

    浅玩CSS3 边框.背景.文本效果 一.边框 box-shadow box-shadow: h-shadow v-shadow blur spread color inset(ontset); //h ...

  5. 【WEB基础】HTML & CSS 基础入门(5)边框与背景

    前面(HTML图片) 漂亮的网页肯定少不了边框与背景的修饰,本篇笔记就是说明如何为网页上的元素设置边框或者背景(背景颜色和背景图片). 之前,先了解一下HTML中的图片元素,因为图片标签的使用非常简单 ...

  6. 06. Web大前端时代之:HTML5+CSS3入门系列~HTML5 画布

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 我们先看看画布的魅力: 初始画布 canvas默认是宽3 ...

  7. 第 17 章 CSS 边框与背景[下]

    学习要点: 1.设置背景 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 一.设置背景 盒模型的尺寸可以通过两种方式实现可见性, ...

  8. 第 17 章 CSS 边框与背景[上]

    学习要点: 1.声明边框 2.边框样式 3.圆角边框 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 一.声明边框 边框的声明有 ...

  9. 第七十四节,css边框与背景

    css边框与背景 学习要点: 1.声明边框 2.边框样式 3.圆角边框  本章主要探讨HTML5中CSS边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 声明边框 边框的声明有三个属性设 ...

随机推荐

  1. delphi 屏幕截屏

    function GetScreenAll: TBitmap; // 截取全屏 var C: TCanvas; begin C := TCanvas.Create; result := TBitmap ...

  2. maven环境终于可以了

    说说maven可以后小小的体会吧,虽然还没有用maven运行过工程,体会是pom.xml中的dependency属性可以帮助管理项目中的jar包,只要在这里配置下需要的jar包,保存后就会自动从中央仓 ...

  3. StoryBoard 简单使用

    StoryBoard简单使用 故事版(storyboard)是一种简洁的图形界面,程序员可以采取拖的形式搭建一个界面,现在使用的xcode默认都会创建一个main.storyboard,作为app的入 ...

  4. Mybatis 后台SQL不输出

    在正确设置log4j.properties之后还是无法输出想要的SQL语句 经过搜索,发现是跟slf4j-api-1.6.1.jar这个jar包冲突了. 删掉之后就正常了, 但是这个包删掉的话acti ...

  5. fulltext不支持Mysql中文全文索引

    Mysql对某表某字段建立了fulltext索引,也不支持中文. 当数据量很大的时候,比较成熟的做法是使用专门的全文索引系统,用这些专业的全文索引系统来分词,以mysql数据库中的数据作为数据源,来分 ...

  6. MediaWiki安装与配置(Ubuntu 10.4)

    实验室准备发布一个网站,本来是准备外包给别人做的,后来自己调研了一下,发现也没有想象的复杂和困难,于是最近一周自己吭哧吭哧地把网站搭好了. 之所以使用Mediawiki,一是考虑到是以实验室发布,不想 ...

  7. ABP入门系列(4)——领域层定义仓储并实现

    一.先来介绍下仓储 仓储(Repository): 仓储用来操作数据库进行数据存取.仓储接口在领域层定义,而仓储的实现类应该写在基础设施层. 在ABP中,仓储类要实现IRepository接口,接口定 ...

  8. 手Q兴趣号的价值在哪里

    拥有5.21亿月活跃用户,如果不做点什么东西出来,实在是浪费至极.如此庞大的用户量,如果能够将内容贡献出来,那将是恐怖的,QQ空间产品就是很好的佐证. QQ群让个体用户能够连接在一起,单个的用户关系链 ...

  9. JDBC数据类型

    JDBC数据类型 JDBC驱动程序Java数据类型转换到适当的JDBC类型然后再将它发送到数据库.它使用默认的大多数数据类型映射.例如,一个Java int转换成一个SQL INTEGER.创建默认映 ...

  10. 换个角度理解云计算之MapReduce(二)

    接上篇 3.Combiner操作 前面讲完Map操作,总结一下就是:一个大文件,分成split1~5,对应于Map1~5,每一个Map处理一个split,每一个split的每一行,会用每一个Map的m ...