CSS入门(主要讲解字体,链接,列表,表格)

一.CSS字体

1.CSS字体属性要定义字体的加粗,大小,文字样式

2.设置字体系列

font-family 属性设置文本的字体系列。

font-family 属性应该设置几个字体名称作为一种"后备"机制,如果浏览器不支持第一种字体,他将尝试下一种字体。

注意: 如果字体系列的名称超过一个字,它必须用引号,如Font Family:"宋体"。

多个字体系列是用一个逗号分隔指明:

p{font-family:"Times New Roman", Times, serif;}

3.常用的字体组合并且通用的字体系列。


Serif 字体

字体文本示例
Georgia, serif

This is a heading

This is a paragraph

"Palatino Linotype", "Book Antiqua", Palatino, serif

This is a heading

This is a paragraph

"Times New Roman", Times, serif

This is a heading

This is a paragraph

sans - serif字体

字体文本示例
Arial, Helvetica, sans-serif

This is a heading

This is a paragraph

Arial Black, Gadget, sans-serif

This is a heading

This is a paragraph

"Comic Sans MS", cursive, sans-serif

This is a heading

This is a paragraph

Impact, Charcoal, sans-serif

This is a heading

This is a paragraph

"Lucida Sans Unicode", "Lucida Grande", sans-serif

This is a heading

This is a paragraph

Tahoma, Geneva, sans-serif

This is a heading

This is a paragraph

"Trebuchet MS", Helvetica, sans-serif

This is a heading

This is a paragraph

Verdana, Geneva, sans-serif

This is a heading

This is a paragraph

Monospace 字体

字体文本示例
"Courier New", Courier, monospace

This is a heading

This is a paragraph

"Lucida Console", Monaco, monospace

This is a heading

This is a paragraph

 4.字体的样式

主要是用于指定斜体文字的字体样式属性。

这个属性有三个值:

  • 正常 - 正常显示文本
  • 斜体 - 以斜体字显示的文字
  • 倾斜的文字 - 文字向一边倾斜(和斜体非常类似,但不太支持)

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title>
<style>
p.normal {font-style:normal;}
p.italic {font-style:italic;}
p.oblique {font-style:oblique;}
</style>
</head>

<body>
<p class="normal">这是一个段落,正常。</p>
<p class="italic">这是一个段落,斜体。</p>
<p class="oblique">这是一个段落,斜体。</p>
</body>

</html>

效果:

5.字体大小

font-size 属性设置文本的大小。

如果你不指定一个字体的大小,默认大小和普通文本段落一样,是16像素(16px=1em)。

 代码示例:

h1 {font-size:40px;}
h2 {font-size:30px;}
p {font-size:14px;}

 6.设置字体的粗细

font-weight属性设置字体的粗细

代码示例: 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title>
<style>
p.normal {font-weight:normal;}
p.light {font-weight:lighter;}
p.thick {font-weight:bold;}
p.thicker {font-weight:900;}
</style>
</head>

<body>
<p class="normal">This is a paragraph.</p>
<p class="light">This is a paragraph.</p>
<p class="thick">This is a paragraph.</p>
<p class="thicker">This is a paragraph.</p>
</body>

</html>

效果:

7.翻译理解

serif(印刷),style(样式),normal(正常的),

italic(斜体字),oblique(斜的),weight(重量),

bold(粗体字),light(微弱的)

二.CSS链接

1.链接样式

链接的样式,可以用任何CSS属性(如颜色,字体,背景等)。

特别的链接,可以有不同的样式,这取决于他们是什么状态。

这四个链接状态是:

  • a:link - 正常,未访问过的链接
  • a:visited - 用户已访问过的链接
  • a:hover - 当用户鼠标放在链接上时
  • a:active - 链接被点击的那一刻

代码示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style>
a:link {color:#000000;}      /* 未访问链接*/
a:visited {color:#00FF00;}  /* 已访问链接 */
a:hover {color:#FF00FF;}  /* 鼠标移动到链接上 */
a:active {color:#0000FF;}  /* 鼠标点击时 */
</style>
</head>
<body>
<p><b><a href="/css/" target="_blank">这是一个链接</a></b></p>
<p><b>注意:</b> a:hover 必须在 a:link 和 a:visited 之后,需要严格按顺序才能看到效果。</p>
<p><b>注意:</b> a:active 必须在 a:hover 之后。</p>
</body>
</html>

2.对链接文本进行修饰

常见的链接样式

根据上述链接的颜色变化的例子,看它是在什么状态。

让我们通过一些其他常见的方式转到链接样式:

文本修饰

text-decoration 属性主要用于删除链接中的下划线:

实例

a:link {text-decoration:none;} 
a:visited {text-decoration:none;} 
a:hover {text-decoration:underline;} 
a:active {text-decoration:underline;}

背景颜色

背景颜色属性指定链接背景色:

实例

a:link {background-color:#B2FF99;} 
a:visited {background-color:#FFFF85;}
 a:hover {background-color:#FF704D;} 
a:active {background-color:#FF704D;}

3.定义一个链接框

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style>
a:link,a:visitedhttps://www.runoob.com/css/
{
	display:block;
	font-weight:bold;
	color:#FFFFFF;
	background-color:#98bf21;
	width:120px;
	text-align:center;
	padding:4px;
	text-decoration:none;
}
a:hover,a:active
{
	background-color:#7A991A;
}
</style>
</head>

<body>
<a href="/css/" target="_blank">这是一个链接</a>
</body>
</html>

效果:

4.翻译理解

link(链接),visited(访问(过去式)),

active(积极的),decoration(装饰)

三.CSS列表

1.CSS 列表属性作用如下:

  • 设置不同的列表项标记为有序列表
  • 设置不同的列表项标记为无序列表
  • 设置列表项标记为图像

2.在 HTML中,有两种类型的列表:

  • 无序列表 ul - 列表项标记用特殊图形(如小黑点、小方框等)
  • 有序列表 ol - 列表项的标记有数字或字母

代码示例:

1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8"> 
5
<title>菜鸟教程(runoob.com)</title> 
6
<style>
7
ul.a {list-style-type:circle;}
8
ul.b {list-style-type:square;}
9
ol.c {list-style-type:upper-roman;}
10
ol.d {list-style-type:lower-alpha;}
11
</style>
12
</head>
13
​
14
<body>
15
<p>无序列表实例:</p>
16
​
17
<ul class="a">
18
  <li>Coffee</li>
19
  <li>Tea</li>
20
  <li>Coca Cola</li>
21
</ul>
22
​
23
<ul class="b">
24
  <li>Coffee</li>
25
  <li>Tea</li>
26
  <li>Coca Cola</li>
27
</ul>
28
​
29
<p>有序列表实例:</p>
30
​
31
<ol class="c">
32
  <li>Coffee</li>
33
  <li>Tea</li>
34
  <li>Coca Cola</li>
35
</ol>
36
​
37
<ol class="d">
38
  <li>Coffee</li>
39
  <li>Tea</li>
40
  <li>Coca Cola</li>
41
</ol>
42
​
43
</body>
44
</html>

即无序列表在ul中定义标记的特殊图形,有序列表在ol中定义标记为数字或字母等

效果:

3.优化标记

代码示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style>
ul
{
	list-style-type:none;
	padding:0px;
	margin:0px;
}
ul li
{
	background-image:url(sqpurple.gif);
	background-repeat:no-repeat;
	background-position:0px 5px; 
	padding-left:14px;
}
</style>
</head>

<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>

</html>

例子解释:

  • ul:
    • 设置列表类型为没有列表项标记
    • 设置填充和边距 0px(浏览器兼容性)
  • ul 中所有 li:
    • 设置图像的 URL,并设置它只显示一次(无重复)
    • 您需要的定位图像位置(左 0px 和上下 5px)
    • 用 padding-left 属性把文本置于列表中

效果:

4.总结所有的CSS列表属性

属性描述
list-style简写属性。用于把所有用于列表的属性设置于一个声明中
list-style-image将图像设置为列表项标志。
list-style-position设置列表中列表项标志的位置。
list-style-type设置列表项标志的类型。

5.翻译理解 

【ul】unordered list(无序列表),【ol】ordered list(有序列表),

【li】list item(列表项) square(正方形),lower(较小的),

upper(上层的),roman(罗马),alpha(按字母顺序的)

四.CSS表格

1.表格边框

样式代码:

<style>
table,th,td
{
	border:1px solid black;
}
</style>

效果:

2.折叠边框

样式代码:

table
{
    border-collapse:collapse;
}
table,th, td
{
    border: 1px solid black;
}

效果:

2.表格宽度和高度

width和height属性定义表格的宽度和高度。

下面的例子是设置100%的宽度,50像素的th元素的高度的表格:

table 
{
    width:100%;
}
th
{
    height:50px;
}

3.设置垂直对齐

使用vertical-align:属性

样式代码:

table, td, th
{
	border:1px solid black;
}
td
{
	height:50px;
	vertical-align:bottom;
}

效果:

4.制定一个个性表格

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title>
<style>
#customers
{
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    width:100%;
    border-collapse:collapse;
}
#customers td, #customers th 
{
    font-size:1em;
    border:1px solid #98bf21;
    padding:3px 7px 2px 7px;
}
#customers th 
{
    font-size:1.1em;
    text-align:left;
    padding-top:5px;
    padding-bottom:4px;
    background-color:#A7C942;
    color:#ffffff;
}
#customers tr.alt td 
{
    color:#000000;
    background-color:#EAF2D3;
}
</style>
</head>

<body>
<table id="customers">
<tr>
  <th>Company</th>
  <th>Contact</th>
  <th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr class="alt">
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr class="alt">
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr class="alt">
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr class="alt">
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
<tr class="alt">
<td>Paris spécialités</td>
<td>Marie Bertrand</td>
<td>France</td>
</tr>
</table>
</body>
</html>

效果:

5.翻译理解

border(边框),solid(立方体),bottom(底部),

collapse(折叠),vertical(垂直),align(排成一行)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值