css 入门基础教程

  发布时间:2010-01-17 01:10:01   作者:佚名   我要评论
css 入门基础,适合刚开始学习css的朋友,最好先有一定的html编写经验。

一、CSS背景控制
可以控制元素的的背景,大概有以下属性
view sourceprint?1 background-color
background-image
background-repeat
background-attachment
background-position
.控制背景色
例如:

复制代码
代码如下:

<html>
<head>
<style type="text/css">
body
{
background-color:#b0c4de;
}
</style>
</head>
<body>
<h1>My CSS web page!</h1>
<p>Hello world! This is a W3Schools.com example.</p>
</body>
</html>


颜色还可以用其他方式表示,如:"red","rgb(255,0,0)","#ff0000"

复制代码
代码如下:

<html>
<head>
<style type="text/css">
h1
{
background-color:#6495ed;
}
p
{
background-color:#e0ffff;
}
div
{
background-color:#b0c4de;
}
</style>
</head>
<body>
<h1>CSS background-color example!</h1>
<div>
This is a text inside a div element.
<p>This paragraph has it's own background color.</p>
We are still in the div element.
</div>
</body>
</html>

.控制背景图

复制代码
代码如下:

<html>
<head>
<style type="text/css">
body {background-image:url('paper.gif')}
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>


.背景重复(如何需要在页面上对背景图像进行平铺,可以使用background-repeat属性)
普通效果

复制代码
代码如下:

<html>
<head>
<style type="text/css">
body
{
background-image:url('gradient2.png');
}
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

平铺效果

复制代码
代码如下:

<html>
<head>
<style type="text/css">
body
{
background-image:url('gradient2.png');
background-repeat:repeat-x;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

4.背景定位
可以用back-ground-position属性改变图像在背景中的位置。

复制代码
代码如下:

<html>
<head>
<style type="text/css">
body
{
background-image:url('img_tree.png');
background-repeat:no-repeat;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>W3Schools background image example.</p>
<p>The background image is only showing once, but it is disturbing the reader!</p>
</body>
</html>

只显示一张图片,如果 去除 background-repeat:no-repeat;<BR>就显示多张图片。
图片置顶,靠右

复制代码
代码如下:

<html>
<head>
<style type="text/css">
body
{
background:#ffffff url('img_tree.png') no-repeat top right;
margin-right:200px;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Now the background image is only show once, and positioned away from the text.</p>
<p>In this example we have also added a margin on the right side, so the background image will never disturb the text.</p>
</body>
</html>

相关文章

  • Html/Css(新手入门第一篇必看攻略)

    下面小编就为大家带来一篇Html/Css(新手入门第一篇必看攻略)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-07-01
  • CSS入门篇之传智播客学习

    结束了HTML学习,接下来我终于揭开了css的真实面纱,在大学时代,一直忙碌去各处收集学习资料,记得当时不知在那位大侠手里拷了有关css相关学习资料,代码看了半天实在费解
    2009-11-13
  • 15个必须阅读的CSS入门文章

    你是新学习CSS?在这个漂亮的学习语言的初始过程可能是一个有点惊人,有很多可以学习它有时很难找出哪里开始。幸运的是有宝贵的大量信息和资源,那里的网络覆盖,通过先进
    2009-08-29
  • CSS 语法 学习css入门者看

    CSS的定义是由三个部分构成:   选择符(selector),属性(properties)和属性的取值(value)。   1.语法: selector {property: value} (选择符 {属性:值})   说明:
    2009-06-28
  • css入门教程之学习网页布局(1)-CSS教程-网页制作-网页教学网

    原文:http://jorux.com/archives/layout-1-if-you-love-css/ 从本篇开始讲述如何用css实现网页的布局,即如何用css控制网页内各个元素的显示位置。如果你是一个初学者
    2008-10-31
  • 学DIV CSS技术,如何入门?

    引用一本书中的一段文字:“当我第一次开始学习汉语时,我的家庭老师老王给了我一本汉英字典、一本汉语语法书和一本初级教程
    2008-10-17
  • CSS入门教程:网页首字下沉-CSS教程-网页制作-网页教学网

    CSS入门教程:网页首字下沉 :first-letter 版本:CSS2  兼容性:IE5.5 语法: Selector : first-letter { sRules } 说明: 设置对象内的第一个字符的
    2008-10-17
  • css是什么_动力节点Java学院整理

    这篇文章主要介绍了css是什么,小编觉得挺不错的,详细的介绍了css的基本入门。现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-06-23

最新评论