Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
eb前端開發(fā)課程:css文本模塊-垂直對齊。
講課人:波波老師。
垂直對齊vertical-align,這個只能用于在表格中的<td>或者<th>才可以垂直對齊其他的標簽,這個垂直對齊的功能是無效的。我們來看代碼。
·先來做一個<div>,VC看看能不能居中對齊,垂直居中。比如點VC把它的高度設(shè)為100px。
·來加個背景顏色,background-color,可以看到它有一個灰色的背景色,給它加個vertical-align,看看這個middle顯然沒有效果。
·再來做一個表格,table,一個tr,再來個td*3,分別做class="vt",class="vc",class="evb"。
·來做個table,做一下樣式,把它的寬度設(shè)為100%,然后td,把它的邊框。
·可以看到這個表格已經(jīng)出來了,這個時候在VC這里做一個居中對齊,可以看到它是居中了,底部對齊,頂部對齊。
·再加兩個.vt,做一個頂部對齊vertical-align:top,可以看到這個vt已經(jīng)頂部對齊了。
·再來做這個.vb的底部對齊,點vb,vertical-align:bottom,這個變成底部對齊了。
演示到這里。
用CSS可以大大提高HTML表格的外觀。
Company | Contact | Country |
---|---|---|
Alfreds Futterkiste | Maria Anders | Germany |
Berglunds snabbk?p | Christina Berglund | Sweden |
Centro comercial Moctezuma | Francisco Chang | Mexico |
Ernst Handel | Roland Mendel | Austria |
Island Trading | Helen Bennett | UK |
K?niglich Essen | Philip Cramer | Germany |
Laughing Bacchus Winecellars | Yoshi Tannamuri | Canada |
Magazzini Alimentari Riuniti | Giovanni Rovelli | Italy |
North/South | Simon Crowther | UK |
Paris spécialités | Marie Bertrand | France |
The Big Cheese | Liz Nixon | USA |
Vaffeljernet | Palle Ibsen | Denmark |
表格邊框
指定CSS表格邊框,使用border屬性。
下面的例子指定了一個表格的Th和TD元素的黑色邊框:
實例
table, th, td
{
border: 1px solid black;
}
請注意,在上面的例子中的表格有雙邊框。這是因為表和th/ td元素有獨立的邊界。
為了顯示一個表的單個邊框,使用 border-collapse屬性。
折疊邊框
border-collapse 屬性設(shè)置表格的邊框是否被折疊成一個單一的邊框或隔開:
實例
table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid black;
}
表格寬度和高度
Width和height屬性定義表格的寬度和高度。
下面的例子是設(shè)置100%的寬度,50像素的th元素的高度的表格:
實例
table
{
width:100%;
}
th
{
height:50px;
}
表格文字對齊
表格中的文本對齊和垂直對齊屬性。
text-align屬性設(shè)置水平對齊方式,像左,右,或中心:
實例
td
{
text-align:right;
}
垂直對齊屬性設(shè)置垂直對齊,比如頂部,底部或中間:
實例
td
{
height:50px;
vertical-align:bottom;
}
表格填充
如果在表的內(nèi)容中控制空格之間的邊框,應(yīng)使用td和th元素的填充屬性:
實例
td
{
padding:15px;
}
表格顏色
下面的例子指定邊框的顏色,和th元素的文本和背景顏色:
實例
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
如您還有不明白的可以在下面與我留言或是與我探討QQ群308855039,我們一起飛!
.表格的寬度 高度 邊框 <width> <height> <border>
2.表格的背景顏色和圖片 <colcr>顏色背景圖片顏色可通過<background> <bgcolor>背景顏色
3.表格以及單元格內(nèi)容的對齊方式 <aligh>分為<right>右對齊 <center>居中對齊 <left>左對齊
4.單元格的填充和間距 <cellspacing>間距 <cellpadding>填充
5.<font>標簽可以設(shè)置字體字號以及顏色
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>優(yōu)化表格</title>
</head>
<body>
<table border="0" width="395" cellpadding="0" cellspacing="0">
<tr>
<td colspan="4" background=""><font color="white"></font><b> 本周暢銷筆記本排名top3<font></font></b></td>
</tr>
</table>
<table>
<tr>
<td>
<table>
<tr>
<td colspan="2">京東超市/td>
</tr>
<tr>
<td colspan="2">< img src="img/1.jpg" alt=""></td>
</tr>
<tr>
<td>< img src="img/人.png" alt=""></td>
<td>< img src="img/羅賓.jpg" alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
*請認真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。