html以及css学习笔记

CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明。

selector {declaration1; declaration2; ... declarationN }
选择器的分组:

h1,h2,h3,h4,h5,h6

{

color:red;

}

派生类选择器:

h2 strong

{

color:red;

}

id 选择器

#green 

{

color:green;

}

<p id="green">这个段落是绿色</p>

相同的id的值一般只能取一次,方便jsp读取元素的值。但是id却可以出现许多次。

#sidebar p {
	font-style: italic;
	text-align: right;
	margin-top: 0.5em;
	}

#sidebar h2 {
	font-size: 1em;
	font-weight: normal;
	font-style: italic;
	margin: 0;
	line-height: 1.5;
	text-align: right;
	}

在css中,类选择器中是以一个点号开始。

.center

{

text-align:right;

}

<head class="center">这段话将在中间显示。</head>

id一样,class也可以作为派生选择器。

.center  head

{

text-align:right;

}

<head class="center">这段话将在中间显示。</head>

属性选择器:

[title]

{

color=red;

}

[title=world]

{

color=red;

}

[title~=world]

{

color=red;

}

<!--属性值包含单词world,适用空格分割的单词-->

[title|=world]

{

color=red;

}

<!--属性值包含单词world,适用于连字符分割的单词-->

外部样式表

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>

内部样式表

<head>
<style type="text/css">
  hr {color: sienna;}
  p {margin-left: 20px;}
  body {background-image: url("images/back40.gif");}
</style>
</head>

内联样式

<p style="color: sienna; margin-left: 20px">
This is a paragraph
</p>

背景的样式:

background-color <!--设置背景色,例子background-color:red-->

background-image <!--设置背景图片,例子background-image:url(图片地址)->

background-repeat  <!--设置背景图片是否重复,例子background-repeat:repeat-->

background-posotion <!--设置背景图片位置,例子background-position-->

background-attachment <!--设置背景图片是否固定,例子background-attachment:fixed-->

文本样式:

text-indent<!--设置首行缩进,例子text-indent:5em右缩进5em-->

text-align<!--设置文字对其方式text-align:center文字中间对其-->

word-spacing<设置单词之间的间隔,例子word-spacing:30px,单词间隔30px>

letter-spacing<设置字符之间的间隔,例子letter-spacing:30px,字母之间间隔30px>

text-decoration<设置修饰方式,例子text-decoration:none,无修饰方式>

text-transfrom<设置文字的大小写,例子text-transfrom:upperase,单词全部大写>

line-height<设置行高,例子line-height:30px,行高为30px>

文字的类型:

font-family<!--设置字体类型,例子font-family:Times,设置字体类型为Times-->

font-size<!--设置字体大小,例子font-size:60px-->

font-weight<!--设置字体笔画宽度,例子font-weight:0.875em-->

font-style<设置字体样式,font-style:italic>

链接:

链接的四种状态:

  • a:link - 普通的、未被访问的链接
  • a:visited - 用户已访问的链接
  • a:hover - 鼠标指针位于链接的上方
  • a:active - 链接被点击的时刻

当为链接的不同状态设置样式时,请按照以下次序规则:

  • a:hover 必须位于 a:link 和 a:visited 之后
  • a:active 必须位于 a:hover 之后

例子:

a.one:link {color:#ff0000;}      a.one:visited {color:#0000ff;}
a.one:hover {color:#ffcc00;}    a.one:active{color:#ffcc00;}

列表的样式:

ul li{list_style_type:square}<!--设置列表样式的图标的前面-->

ul li{list_style_image:url(图片地址)}<!--设置列表样式的图片-->

ul li{list_style_position:inside/outside}<!--确定标志出现在列表项内容之外还是内容内部-->

表格:

表格边框以及折叠边框

例子:

table
{

     width:100%;<!--设置表的宽度-->
     border-collapse:collapse;<!--设置边框为折叠-->
}
table, td, th
{

     border:1px solid black;<!--设置边框-->

}

td
{

height:50px; <!--文本的高度-->
text-align:right;<!--文本的对齐方式-->
vertical-align:bottom<!--竖直方向对其-->
padding:15px;<!--设置边框距离-->
}

轮廓的样式:

outline-color 设置轮廓的颜色

outline-style 设置轮廓的样式

outline-with  设置轮廓的宽度

p.one
{
outline-color:#00ff00;
outline-style:solid;
outline-width:thin;
}

定位:相对定位 决定定位 固定定位

position:relative;
left:-20px

position:absolute;
left:100px;
top:150px

position:fixed;
top:30px;
right:5px;

position:absolute;
left:0px;
top:0px;
z-index:-1

子元素选择器:

这个规则会把第一个 h1 下面的两个 strong 元素变为红色,但是第二个 h1 中的 strong 不受影响:

<h1>This is <strong>very</strong> <strong>very</strong> important.</h1>
<h1>This is <em>really <strong>very</strong></em> important.</h1>
相邻兄弟选择器:

li + li {font-weight:bold;}

伪类:

p:first-child {
  color: red;

  } 

图片透明:

img
{
opacity:0.4;
filter:alpha(opacity=40); /* 针对 IE8 以及更早的版本 */
}

html段落:

<p>这是一个段落。</p>

html水平线:

<hr/>

html换行:

<br/>

html注释:

<!--这是一个注释-->

html标题:

<h1>到<h6> 

<h1>这是标题 1</h1>  字体由大到小

html粗体文本

<b>粗体字</b>

<big>大号字体</big>

<strong>加重语气</strong>

<em>定义着重语句</em>

<i>定义斜体字</i>

<small>定义小号字</small>

<sub>定义下标字</sub>

<sup>定义上标字</sup>

<ins>定义插入字</ins>

<del>定义删除字</del>

<code>定义计算机代码</code>

<kbd>定义键盘输入信息</kbd>

<tt>定义打印机代码</tt>

<var>定义计算机变量</var>

<pre>定义预格式文本</pre>

<samp>定义计算机代码样本</samp>

<address>定义地址</address>

<abbr>定义缩写</abbr>

<acronym>定义首字母缩写</acronym>

<bdo>文字方向</bdo>

例子:

<bdo dir="rtl">this is a text</bdo>

<blockquote>定义长的长的引用</blockquote>

<q>定义短引用</q>

例子:

这是短的引用:<q>这是一个引用</q>

<cite>著作的标题</cite>

<var>定义变量</var>

在新的浏览器打开链接:

<a href="http://www.w3school.com.cn/" target="_blank">Visit W3School!</a>

链接到同一界面的不同位置:

<a href="#C4">查看 Chapter 4。</a>

<h2><a name="C4">Chapter 4</a></h2>

发送邮件:

<a href="mailto:[email protected]?subject=Hello%20again">发送邮件</a>

插入图像:

<img src="/i/eg_mouse.jpg" width="128" height="128" />

为图片替换文本:

<img src="/i/eg_goleft123.gif" alt="向左转" />

表格:

<table border="1">
<tr>
  <td>Some text</td>
  <td>Some text</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>Some text</td>
</tr>
</table>

<h4>横跨两列的单元格:</h4>
<table border="1">
<tr>
  <th>姓名</th>
  <th colspan="2">电话</th>
</tr>
<tr>
  <td>Bill Gates</td>
  <td>555 77 854</td>
  <td>555 77 855</td>
</tr>
</table>


<h4>横跨两行的单元格:</h4>
<table border="1">
<tr>
  <th>姓名</th>
  <td>Bill Gates</td>
</tr>
<tr>
  <th rowspan="2">电话</th>
  <td>555 77 854</td>
</tr>
<tr>
  <td>555 77 855</td>
</tr>
</table>

<ol start="50">
  <li>咖啡</li>
  <li>牛奶</li>
  <li>茶</li>
</ol>

html背景 背景色 字体颜色

<body bgcolor="#d0d0d0"  text="yellow"></body>

<body background="/i/eg_bg_06.gif"></body>

html脚本

<script type="text/javascript">
document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>

html标题

<title>标题不会显示在文档区</title>

html所有连接同一个目标

<base target="_blank" />

html的meta元素

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<meta name="author"
content="w3school.com.cn">

<meta name="revised"

content="David Yang,8/1/07">
<meta name="generator"
content="Dreamweaver 8.0en">

<meta name="description"
content="HTML examples">
<meta name="keywords"
content="HTML, DHTML, CSS, XML, XHTML, JavaScript, VBScript">

html从定向

<meta http-equiv="Refresh" content="5;url=http://www.w3school.com.cn" />

html的link元素

<link rel="stylesheet" type="text/css" href="mystyle.css" />
html实体:

&#160

html框架 垂直框架:

<frameset cols="25%,50%,25%">
  <frame src="/example/html/frame_a.html">
  <frame src="/example/html/frame_b.html">
  <frame src="/example/html/frame_c.html">
</frameset>

水平架构:

<frameset rows="25%,50%,25%">
  <frame src="/example/html/frame_a.html">
  <frame src="/example/html/frame_b.html">
  <frame src="/example/html/frame_c.html">
</frameset>

浏览器不支持框架

<frameset cols="25%,50%,25%">
  <frame src="/example/html/frame_a.html" noresize="noresize"/>
  <frame src="/example/html/frame_b.html"/>
  <frame src="/example/html/frame_c.html"/>
<noframes>
<body>您的浏览器无法处理框架!</body>
</noframes>
</frameset>

html导航框架:

<frameset cols="120,*">
  <frame src="/example/html/html_contents.html">
  <frame src="/example/html/frame_a.html" name="showframe">
</frameset>

html内联框架:

<iframe src="/example/html/iframe.html" name="iframe_a"></iframe>

<p><a href="http://www.baidu.com" target="iframe_a">www.baidu.com</a></p>
































猜你喜欢

转载自blog.csdn.net/zq4132/article/details/78913029