如何在表格边框中使用宽度?

问题描述 投票:0回答:1

我试图在我的论坛中实现cellpaddingcellspacing,但我无法让width="100%"使用它。

在我的CSS中使用cellpaddingcellspacing时是否可以设置宽度?

.categories div.category td tr{
   padding: 80px;
   width: 500px; 
}
echo '
  <table class="categories">
    <caption>Category: ', $row2['category'], '</caption>
    <thead>
      <tr>
        <td colspan="3">
          <th colspan="3"><a href="create_music_sub.php?cat='.$row2['id'].'&admin='.$row2['admin'].'">
            Click here to Create Sub Category
          </a></th>
        </td>
      </tr><tr>
        <div class="category"><th scope="col">Category</th></div>
        <th scope="col">Creator</th>
        <th scope="col">Date Created</th>
      </tr>
    </thead><tbody>';
html css
1个回答
0
投票

如果你的意思是将表的宽度设置为100%,这是有效的。至于你提供的代码有错误:

  1. 如果你想使用th,你不要使用td
  2. div.category应该在tr > th里面而不包装它。
  3. 当您发布问题时,请删除php片段并为我们提供一个工作小提琴,以便能够更快地帮助您。

请查看代码,看看我做了哪些不同的事情。我认为问题出在你的HTML中

table{
  border:1px solid black;
  width: 100%;
}

tr, th, td{
  border:1px solid black;
}

td,th{
  padding: 10px;
}

/*If you want the last column to be smaller you can change one of them to a certain width*/

.creator{
  width:20%;
}
<table class="categories">
	<caption>Category: 1</caption>
	<thead>
		<tr>
			<th colspan="3">
				<a href="">Click here to Create Sub Category</a>
			</th>
		</tr>
		<tr>
			<th scope="col">
				<div class="category">Category</div>
			</th>
			<th scope="col">Creator</th>
			<th scope="col">Date Created</th>
		</tr>
    
    <tr>
			<th colspan="2" scope="col">
				<div class="category">Category</div>
			</th>
			<th scope="col">Creator</th>
		</tr>
	</thead>
</table>


<table class="categories">
	<caption>Category: 1</caption>
	<thead>
		<tr>
			<th colspan="3">
				<a href="">Click here to Create Sub Category</a>
			</th>
		</tr>
		<tr>
			<th scope="col">
				<div class="category">Category</div>
			</th>
			<th scope="col">Creator</th>
			<th scope="col">Date Created</th>
		</tr>
    
    <tr>
			<th colspan="2" scope="col">
				<div class="category">Category</div>
			</th>
			<th scope="col" class="creator">Creator</th>
		</tr>
	</thead>
</table>
© www.soinside.com 2019 - 2024. All rights reserved.