国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

table中cesllspacing與cellpadding的區(qū)別詳解

2024-08-26 00:14:04
字體:
供稿:網(wǎng)友

table是什么?它是由一個(gè)個(gè)cell單元格構(gòu)成的,在表格中,<td>的個(gè)數(shù)取決于每行<tr>中包裹的cell單元格個(gè)數(shù)!此外,默認(rèn)table表格在沒有添加css樣式<style type="text/css">table tr td,th{border:1px solid #000;}之前,在瀏覽器中顯示是沒有表格線的;

html中常見table寫法:A.<tr>…</tr>:表格的一行,有幾對(duì)tr表格就有幾行; B.<td>…</td>:表格的一個(gè)單元格,一行中包含幾對(duì)<td>...</td>,說明一行中就有幾列; C.<th>…</th>:表格的頭部的一個(gè)單元格,表格表頭,文本默認(rèn)為粗體并且居中顯示;D.<table summary="表格簡(jiǎn)介文本">/*摘要的內(nèi)容是不會(huì)在瀏覽器中顯示出來的。它的作用是增加表格的可讀性(語義化),使搜索引擎更好的讀懂表格內(nèi)容,還可以使屏幕閱讀器更好的幫助特殊用戶讀取表格內(nèi)容。*/ E.caption標(biāo)簽,為表格添加標(biāo)題和摘要,標(biāo)題用以描述表格內(nèi)容,標(biāo)題的顯示位置:表格上方

 <table border="" cellspacing="" cellpadding="">    <tr><th>Header</th></tr>     <tr><td>Data</td></tr> </table>
<table border="" cellspacing="" cellpadding="" summary="">         <caption></caption>         <tr><th>今天星期五/th></tr>         <tr><td>today is Friday</td></tr> </table>

言歸正傳,cellpadding 和cellspacing區(qū)別,先看下面一組表格圖片與cellspacing代碼的對(duì)比:

<!DOCTYPE HTML><html>    <head>        <meta charset="utf-8">        <title>table中cellspacing的區(qū)別</title>        <style type="text/css">            table{                margin-bottom: 50px;            }            .ceshi{                border-spacing: 20px;                /*Specifies the distance between the borders of adjoining cells in a table. */            }        </style>    </head>    <table width="600" cellspacing="0" bordercolor="#333" border="1">        <caption>第一個(gè)單元格</caption>        <tr>            <td>測(cè)試1</td>            <td>測(cè)試2</td>            <td>測(cè)試3</td>        </tr>    </table>    <table width="600" cellspacing="20" bordercolor="#333" border="1">        <caption>第二個(gè)單元格</caption>        <tr>            <td>測(cè)試1</td>            <td>測(cè)試2</td>            <td>測(cè)試3</td>        </tr>    </table>    <table width="600" bordercolor="#333" border="1" class="ceshi">        <caption>第三個(gè)單元格</caption>        <tr>            <td>測(cè)試1</td>            <td>測(cè)試2</td>            <td>測(cè)試3</td>        </tr>    </table></html>

比較代碼,最上面的兩個(gè)表格只有cellspacing的設(shè)置不同,一個(gè)為”0“,一個(gè)為”20“,顯示的結(jié)果就是第一個(gè)表格的每個(gè)單元格之間的距離為0,第二個(gè)表格的每個(gè)單元格之間的距離為20;延伸下:第二個(gè)表格與第三個(gè)表格一致,但是第三個(gè)表格沒有設(shè)置cellspacing,我們發(fā)現(xiàn)這個(gè)border-spacing: 20px;與cellspacing="20" 的結(jié)果一樣一樣的,e.g小結(jié):cellspacing屬性用來指定表格各單元格之間的空隙。此屬性的參數(shù)值是數(shù)字,表示單元格間隙所占的像素點(diǎn)數(shù)。

<!DOCTYPE HTML><html>    <head>        <meta charset="utf-8">        <title>tabl表格中cellpadding的區(qū)別</title>        <style type="text/css">            table{                margin-bottom: 50px;            }        </style>    </head>    <body>        <table width="600px" border="1" bordercolor="#ccc" cellpadding="0">            <tr>                <th>我是快樂的cell表格</th>                <th>我是快樂的cell表格</th>                <th>我是快樂的cell表格</th>            </tr>        </table>        <table width="600px" border="1" bordercolor="#ccc" cellpadding="20">            <tr>                <th>我是快樂的cell表格</th>                <th>我是快樂的cell表格</th>                <th>我是快樂的cell表格</th>            </tr>        </table>    </body></html>

從上面的代碼運(yùn)行展示結(jié)果來看:兩個(gè)表格只有cellpadding代碼值不同,第一個(gè)表格中"我是快樂的cell表格"這幾個(gè)字離它所在的單元格為0,那是因?yàn)樵O(shè)置了cellpadding="0"的原因;第二個(gè)表格中的"我是快樂的cell表格"這幾個(gè)字離它所在的單元格比較遠(yuǎn),那是因?yàn)閏ellpadding="20",也就是說"我是快樂的cell表格"離它所在的單元格的邊界的距離為20像素。簡(jiǎn)單的說,cellpadding的值等于多少,那表格內(nèi)的單元格從自身邊界開始向內(nèi)保留多少空白,單元格里的元素永遠(yuǎn)都不會(huì)進(jìn)入那些空白里。||注意 cellpadding屬性用來指定單元格內(nèi)容與單元格邊界之間的空白距離的大小。此屬性的參數(shù)值也是數(shù)字,表示單元格內(nèi)容與上下邊界之間空白距離的高度所占像素點(diǎn)數(shù)以及單元格內(nèi)容與左右邊界之間空白距離的寬度所占的像素點(diǎn)數(shù)。

e.g小結(jié):cellspacing代表的是單元格與單元格之間的距離,cellpadding表示的是單元格內(nèi)容與邊框的距離;前者的理解像margin,后者像padding;巢(cell)--表格的內(nèi)容;巢補(bǔ)白(表格填充)(cellpadding)--代表巢外面的一個(gè)距離,用于隔開巢與巢空間;巢空間(表格間距)(cellspacing)--代表表格邊框與巢補(bǔ)白的距離,也是巢補(bǔ)白之間的距離

拓展一:表格的行與列如何合并?colspan跨列合并,rowspan跨行合并

代碼展示:

<!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <title>colspan與rowspan的區(qū)別</title>        <style type="text/css">            table{                margin: 0 auto;                margin-bottom: 50px;                text-align: center;            }        </style>    </head>    <body>    <table width="600" cellpadding="10" cellspacing="2" border="1" bordercolor="#ccc">        <caption>正常展示:一行三列</caption>        <tr>            <td>說點(diǎn)啥了,不知道</td>            <td>說點(diǎn)啥了,不知道</td>            <td>說點(diǎn)啥了,不知道</td>        </tr>    </table>    <table width="600" cellpadding="10" cellspacing="2" border="1" bordercolor="#ccc">        <caption>現(xiàn)在要展示一行二列,怎么辦?colspan跨列合并</caption>        <tr>            <td>說點(diǎn)啥了,不知道</td>            <td colspan="2">說點(diǎn)啥了,不知道</td>            <!-- <td>說點(diǎn)啥了,不知道</td> -->        </tr>    </table>    <!-- ========無情分割線========================================================== -->    <table width="600" cellpadding="10" cellspacing="2" border="1" bordercolor="#ccc">        <caption>正常展示:二行二列</caption>        <tr>            <td>說點(diǎn)啥了,不知道</td>            <td>說點(diǎn)啥了,不知道</td>        </tr>        <tr>            <td>說點(diǎn)啥了,不知道</td>            <td>說點(diǎn)啥了,不知道</td>        </tr>    </table>    <table width="600" cellpadding="10" cellspacing="2" border="1" bordercolor="#ccc">        <caption>現(xiàn)在要展示一行二列,怎么辦?rowspan跨行合并</caption>        <tr>            <td rowspan="2">說點(diǎn)啥了,不知道</td>            <td>說點(diǎn)啥了,不知道</td>        </tr>        <tr>            <!-- <td>說點(diǎn)啥了,不知道</td> -->            <td>說點(diǎn)啥了,不知道</td>        </tr>    </table>    </body></html>

拓展二:如何合并表格邊框?border-collapse: collapse;

<!-- 合并表格單元格 -->    <style type="text/css">        table{            border-collapse: collapse;            /* border-collapse: separate; */            /*Indicates whether the row and cell borders of a table are joined in a single border or detached as in standard HTML. */        }    </style>    <table width="600" cellpadding="10" cellspacing="2" border="1" bordercolor="#ccc">        <tbody>            <tr>                <td>單元格1</td>                <td>單元格2</td>                <td>單元格3</td>            </tr>        </tbody>    </table>

最后chrome瀏覽器中,系統(tǒng)默認(rèn)的表格邊框顏色grey,邊框間距為2等等

/* user agent stylesheet */        /* table {            display: table;            border-collapse: separate;            border-spacing: 2px;            border-color: grey;        } */        /*         border="1"默認(rèn)等于border="1px"        border-top-width: 1px;        border-right-width: 1px;        border-bottom-width: 1px;        border-left-width: 1px; */        /*        bordercolor返回或設(shè)置對(duì)象的邊框顏色        bordercolor:W3C - String         Specifies the color of the border of the element. Specify either a color name or RGB color code. */

到此這篇關(guān)于table中cesllspacing與cellpadding的區(qū)別詳解的文章就介紹到這了,更多相關(guān)table中cesllspacing與cellpadding內(nèi)容請(qǐng)搜索武林網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持武林網(wǎng)!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 肇东市| 汝城县| 印江| 盘山县| 襄垣县| 兴文县| 观塘区| 岳池县| 宜丰县| 天门市| 江达县| 城步| 北安市| 北川| 呼图壁县| 绥棱县| 台东县| 四平市| 霍城县| 西乡县| 增城市| 阿克苏市| 花垣县| 宜宾市| 垦利县| 白玉县| 图木舒克市| 淮阳县| 广河县| 五华县| 安化县| 汤阴县| 尤溪县| 大悟县| 伊吾县| 团风县| 彭山县| 泾阳县| 察哈| 库尔勒市| 军事|