html+css复习总结

1、插入视频

<head>

var myVideo=document.getElementById("video1");

function playPause()

if (myVideo.paused) 

myVideo.play(); 

else 

myVideo.pause(); 

</head>


<body>

<div style="text-align:center;">

        <button onclick="playPause()">播放/暂停</button>

        <video id="video1" width="420" style="margin-top:15px;">

              <source src="movie.ogg" type="video/ogg">

              <source src="movie.mp4" type="video/mp4">

                    Your browser does not support the video tag.

        </video>

</div>

</body>



2.播放音频

<audio src="song.ogg" controls="controls">

Your browser does not support the audio tag.

</audio>


3.HTML拖放

思路:1)设置元素可拖放 2)设置存放拖动的值的变量 3)获取拖之后的数据并插入

<head>

<script type='text/javascript'>

function drag(ev)

{

ev.dataTransfer.setData("Text",ev.target.id);

}

function allowDrop(ev)

{

ev.preventDefault();

}

function drop(ev)

{

ev.preventDefault();

var data=ev.dataTransfer.getData("Text");

ev.target.appendChild(document.getElementById(data));

}

</script>

</head>

<body>

<div id="div1" ondrop="drop(event)"

ondragover="allowDrop(event)"></div>

<img id="drag1" src="img_logo.gif" draggable="true"

ondragstart="drag(event)" width="336" height="69" />

</body>



4.绘制图形

<script type="text/javascript">

var c=document.getElementById("myCanvas");

var cxt=c.getContext("2d");

cxt.fillStyle="#FF0000";

cxt.fillRect(0,0,150,75);

</script>


<canvas id="myCanvas" width="200" height="100"></canvas>

--------------------------------

<script type="text/javascript">

var c=document.getElementById("myCanvas");

var cxt=c.getContext("2d");

cxt.moveTo(10,10);

cxt.lineTo(150,50);

cxt.lineTo(10,50);

cxt.stroke();

</script>


<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">

Your browser does not support the canvas element.

</canvas>


5.矢量图

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="190">

  <polygon points="100,10 40,180 190,60 10,60 160,180"

  style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />

</svg>



6.使用地理位置

var x=document.getElementById("demo");function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} }function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "
Longitude: " + position.coords.longitude; }var x=document.getElementById("demo");function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} }function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "
Longitude: " + position.coords.longitude; }var x=document.getElementById("demo");function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} }function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "
Longitude: " + position.coords.longitude; }var x=document.getElementById("demo");function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} }function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "
Longitude: " + position.coords.longitude; }

var x=document.getElementById("demo");function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} }function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "
Longitude: " + position.coords.longitude; }var x=document.getElementById("demo");

function getLocation() { 

 if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} 

 }

function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "
Longitude: " + position.coords.longitude; 

 }



7.换行

<br />



8.样式

<h1 style="text-align:center">This is a heading</h1>

<p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p>


9.引用外部样式

<head>

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

</head>



10.引用内部样式

<style type="text/css">

body {background-color: red}

p {margin-left: 20px}

.city {

float: left;

margin: 5px;

padding: 15px;

width: 300px;

height: 300px;

border: 1px solid black;

}

</style>



10.加入链接

<a href='http://www.3cschool.com.cn/'  target='_blank'>hahaha</a>



11.加入图像,如果图像显示不出来,就显示数字

<img src='da' alt='asdf'>



12.水平表格和表头,表单元格内边距,单元格外边距

<table border="1" cellpadding="10" cellspacing="10"  bgcolor="red" background="/i/eg_bg_07.gif">

<caption>这里是有表头的表格标题</caption>

<tr>

  <th>姓名</th>

  <th>电话</th>

  <th>电话</th>

</tr>

<tr>

  <td>Bill Gates</td>

  <td>555 77 854</td>

  <td>555 77 855</td>

</tr>

</table>



13.垂直表格

<table border="1">

<tr>

  <th>姓名</th>

  <td>Bill Gates</td>

</tr>

<tr>

  <th>电话</th>

  <td>555 77 854</td>

</tr>

<tr>

  <th>电话</th>

  <td>555 77 855</td>

</tr>

</table>

</body>

</html>



14.空单元格

&nbsp;



15.横跨两行的单元格

<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>



16.横跨两列的单元格

<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>



17.无序列表或者有序列表

<ul type="disc">

<li>苹果</li>

<li>香蕉</li>

<li>柠檬</li>

<li>桔子</li>

</ul> 

---------------------------

<ol>

<li>Coffee</li>

<li>Milk</li>

</ol>



18.块

 div或者span



19.下划线

<hr />



20.表单

<form action="action_page.php" method="GET" target="_blank" accept-charset="UTF-8"

ectype="application/x-www-form-urlencoded" autocomplete="off" novalidate>

First name:<br>

<select name='cars'>

<option value="volvo">Volvo</option>

<option value="saab">Saab</option>

<option value="fiat">Fiat</option>

<option value="audi">Audi</option>

</select>

<br>

<textarea name="message" rows="10" cols="30">

The cat was playing in the garden.

</textarea>

<br>

<button type="button" onclick="alert('Hello World!')">Click Me!</button>

<br>

<input type="text" name="firstname">

<br>

<input type="password" name="psw">

<br>

<input type="checkbox" name="vehicle" value="Bike">I have a bike

<br>

<input type="checkbox" name="vehicle" value="Car">I have a car

<br>

<input type="radio" name="sex" value="male" checked>Male

<br>

<input type="submit" value="Submit">

<br>



21.input属性值

input属性值如value,readonly,disabled,size,maxlength

<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">



22.派生选择器

h2 strong{ color: blue; }


23.属性选择器

1)第一种

[title]{color:red;}

------

<body>

<h2 title="Hello world">Hello world</h2>

<a title="W3School" href="http://w3school.com.cn">W3School</a>

</body>

2)第二种

[title~=hello]

{

color:red;

}

------------

<h2 title="hello world">Hello world</h2>

<p title="student hello">Hello W3School students!</h1>


实战

input[type="text"]

{

  width:150px;

  display:block;

  margin-bottom:10px;

  background-color:yellow;

  font-family: Verdana, Arial;

}



24.css背景

background-color,  background-image



25.css文本

1)首行缩进

p {text-indent: 5em;}

p {text-indent: 20%;}

2)text-align:center 与 <CENTER>区别

<CENTER> 不仅影响文本,还会把整个元素居中。

3)word-spacing

word-spacing 属性可以改变字(单词)之间的标准间隔。

4)letter-spacing

letter-spacing 属性与 word-spacing 的区别在于,字母间隔修改的是字符或字母之间的间隔

5)字符转换

text-transform 属性处理文本的大小写,属性有:

none,uppercase,lowercase,capitalize

6)文本划线

text-decoration 有 5 个值:

none

underline

overline

line-through

blink(文本闪烁)

7)处理空白符

white-space 属性会影响到用户代理对源文档中的空格、换行和 tab 字符的处理。

如果 white-space 属性的值为 pre,空白符不会被忽略,否则=normal它会把所有空白符合并为一个空格,否则=nowrap,它会防止元素中的文本换行,除非使用了一个 br 元素。

<p>This paragraph has many

    spaces          in it.</p>

---------

p {white-space: normal;}




26.字体样式font-family

Serif 字体

Sans-serif 字体

Monospace 字体

Cursive 字体

Fantasy 字体



27.字体斜体格式

font-style 属性最常用于规定斜体文本。

该属性有三个值:

normal - 文本正常显示

italic - 文本斜体显示

oblique - 文本倾斜显示



28.点击样式

链接的四种状态:

a:link - 普通的、未被访问的链接

a:visited - 用户已访问的链接

a:hover - 鼠标指针位于链接的上方

a:active - 链接被点击的时刻



29.ul列表

ul {list-style-type : square}



30.css表格

由于 table/th/td 元素都有独立的边框,如果需要把表格显示为单线条边框,请使用border-collapse属性

table

  {

  border-collapse:collapse;

  }

table, td, th

  {

  border:1px solid black;

vertical-align:bottom;

  }



31.css轮廓

outline:#00ff00 dotted thin;

outline:#00ff00 solid 5px;



32.css框模型

* {

  margin: 0;

  padding: 0;

}



33.css边框

p.aside {border-style: solid dotted dashed double;border-width: 15px 5px 15px 5px;}



34.css外边距合并

当一个元素出现在另一个元素上面时,第一个元素的下外边距与第二个元素的上外边距会发生合并。



35.css定位

position属性有:relative, absolute, fixed.

绝对定位的元素的位置相对于最近的已定位祖先元素,如果元素没有已定位的祖先元素,那么它的位置相对于最初的包含块

#box_relative {

  position: relative;

  left: 30px;

  top: 20px;

}



36.浮动

为图像添加了边距,这样就可以把文本推离图像:上和右外边距是 0px,下外边距是 15px,

img

{

float:right;

border:1px dotted black;

margin:0px 0px 15px 20px;

}



37.选择器

h2, p {color:gray;}


38.属性选择器

为了将同时有 href 和 title 属性的 HTML 超链接的文本设置为红色

a[href][title]

{

color:red;

}

将某个指定文档的超链接变成红色

a[href="http://www.w3school.com.cn/about_us.asp"]{

color: red;

}

选择 class 属性中包含 important 的元素

p[class~="important"] {color: red;}

p.important 和 p[class="important"] 应用到 HTML 文档时是等价的。

选择 abc 属性值以 "def" 开头的所有元素:[abc^="def"]

选择 abc 属性值以 "def" 结尾的所有元素:[abc$="def"]

选择 abc 属性值中包含子串 "def" 的所有元素:[abc*="def"]

选择 lang 属性等于 en 或以 en- 开头的所有元素:*[lang|="en"] {color: red;}




39.后代选择器

h1 em {color:red;}

为包含边栏的 div 指定值为 sidebar 的 class 属性设置:div.sidebar {background:blue;}

把第一个 h1 下面的两个 strong 元素变为红色:h1>strong {color:red;}



40.相邻兄弟选择器

选择紧接在 h1 元素后出现的段落:h1 + p {margin-top:50px;}



41.伪类选择器

a:visited{color: #00FF00}/* 已访问的链接 */

将作为某元素第一个子元素的所有 p 元素设置为粗体:  p:first-child {font-weight: bold;}

p 元素的第一行文本进行格式化:  

p:first-line

  {

  color:#ff0000;

  font-variant:small-caps;

  }



42.css对齐

把左和右外边距设置为 auto,规定的是均等地分配可用的外边距

.center{margin-left:auto;

margin-right:auto;width:70%;background-color:#b0e0e6;}


使用 position 属性进行左和右对齐

.right{position:absolute;right:0px;width:300px;background-color:#b0e0e6;}



43.css高度

line-heightmax-heightmax-widthmin-height


44.CSS clear 属性

图像的左侧和右侧均不允许出现浮动元素

img

  {

  float:left;

  clear:both;

  }



45.css导航栏

把段落元素设置为内联元素: p {display: inline}

而div 元素不会显示出来:div {display: none}

此元素将显示为块级元素,此元素前后会带有换行符:block

行内块元素:inline-block

此元素会作为列表显示:list-item

使 h2 元素不可见:h1.invisible {visibility:hidden}



46.css图片

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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,496评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,407评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,632评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,180评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,198评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,165评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,052评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,910评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,324评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,542评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,711评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,424评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,017评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,668评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,823评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,722评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,611评论 2 353