HTML 基础2

当浏览器读到一个样式表,它就会按照这个样式表来对文档进行格式化。有以下三种方式来插入样式表:

  • 外部样式表
  • 内部样式
  • 内联样式

外部样式表

当样式需要被应用到很多页面的时候,外部样式表将是理想的选择。使用外部样式表,你就可以通过更改一个文件来改变整个站点的外观

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

内部样式表

单个文件需要特别样式时,就可以使用内部样式表。你可以在 head 部分通过 <style> 标签定义内部样式表。

<head>
<style type="text/css">
body {background-color: red}
p {margin-left: 20px}
</style>
</head>

内联样式

特殊的样式需要应用到个别元素时,就可以使用内联样式。 使用内联样式的方法是在相关的标签中使用样式属性。样式属性可以包含任何 CSS 属性。

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

超链接

在新窗口打开:

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

链接到同一个页面的不同位置:

<a href="#C4">查看 Chapter 4。</a>(根据标签ID)

跳出框架:

<a href="/index.html" target="_top">请点击这里!</a>

 

图像

背景图片:<body background="/i/eg_background.jpg">

排列图片:<p>图像 <img src="/i/eg_cute.gif" align="bottom"> 在文本中</p>

  align属性

align="bottom":图片底部跟文字对齐

align="middle":图片中间跟文字对齐

align="bottom":默认,图片顶部跟文字对齐

浮动图片:<img src ="/i/eg_cute.gif" align ="left"> 

left/right:浮动在文字左侧/右侧

为图片显示替换文本:<img src="/i/eg_goleft123.gif" alt="向左转" />

  当图像不能显示,会显示alt属性的替换文本

图像映射:

<img
src="/i/eg_planets.jpg"
border="0" usemap="#planetmap"
alt="Planets" />

<map name="planetmap" id="planetmap">

<area
shape="circle"
coords="180,139,14"
href ="/example/html/venus.html"
target ="_blank"
alt="Venus" />

<area
shape="circle"
coords="129,161,10"
href ="/example/html/mercur.html"
target ="_blank"
alt="Mercury" />

</map>

原文地址:https://www.cnblogs.com/jszfy/p/12761931.html