在css中,可以使用width屬性設(shè)置td寬度,只需要給td元素設(shè)置“width:寬度值;”樣式即可。width屬性設(shè)置元素的寬度,該屬性定義元素內(nèi)容區(qū)的寬度,在內(nèi)容區(qū)外面可以增加內(nèi)邊距、邊框和外邊距。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
css直接使用width屬性設(shè)置表格td的寬度:
示例:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>document</title> <style> td.box1 { width:10%; border: medium solid red } td.box3 { width:15%; border: medium solid red } td.box5 { width:20%; border: medium solid red } td.box4 { width:45%; border: medium solid red } </style> </head> <body> <table width="100%"> <td class="box1">10%</td> <td class="box1">10%</td> <td class="box3">15%</td> <td class="box4">45%</td> <td class="box5">20%</td> </table> </body> </html>
效果圖:
width 屬性設(shè)置元素的寬度。
這個屬性定義元素內(nèi)容區(qū)的寬度,在內(nèi)容區(qū)外面可以增加內(nèi)邊距、邊框和外邊距。
屬性值:
-
auto 默認值。瀏覽器可計算出實際的寬度。
-
length 使用 px、cm 等單位定義寬度。
-
% 定義基于包含塊(父元素)寬度的百分比寬度。
-
inherit 規(guī)定應該從父元素繼承 width 屬性的值。
推薦學習:css視頻教程