gpt4 book ai didi

html - 从给定单元格开始 rowspan 和 colspan 并减少 rowspan 的填充

转载 作者:太空宇宙 更新时间:2023-11-04 09:00:37 24 4
gpt4 key购买 nike

我正在编写一个动态创建 HTML 表格的 PHP 脚本。

有两件东西丢失了,找不到相关信息。

我想减少 rowspan 单元格的“填充”,它在水平方向上太大了。您可以使用什么来修改内部字符串和单元格末尾之间的间距?

我还想从第 3 行到最后一行开始 rowspan,并从第 3 列到最后一列开始 colspan。这能做到吗?

HTML 源代码,如果您想查看表格的外观:

table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
<table style="width:50%">
<tr>
<th colspan="17">Weight, in Kg</th>
</tr>
<tr>
<th rowspan="11">Height, in cm</th>
</tr>
<tr>
<th></th>
<th>40</th>
<th>45</th>
<th>50</th>
<th>55</th>
<th>60</th>
<th>65</th>
<th>70</th>
<th>75</th>
<th>80</th>
<th>85</th>
<th>90</th>
<th>95</th>
<th>100</th>
<th>105</th>
<th>110</th>
</tr>
<tr>
<th>160</th>
<td>15</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>35</td>
<td>37</td>
<td>39</td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<th>165</th>
<td>14</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>34</td>
<td>36</td>
<td>38</td>
<td>40</td>
</tr>
<tr>
<th>170</th>
<td>13</td>
<td>15</td>
<td>17</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>24</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>36</td>
<td>38</td>
</tr>
<tr>
<th>175</th>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>35</td>
</tr>
<tr>
<th>180</th>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
<td>33</td>
</tr>
<tr>
<th>185</th>
<td>11</td>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
</tr>
<tr>
<th>190</th>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
</tr>
<tr>
<th>195</th>
<td>10</td>
<td>11</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<th>200</th>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>26</td>
<td>27</td>
</tr>
</table>

最佳答案

创建一个 2x2 “填充” 单元格。然后开始列标签单元格一<tr>之后。您基本上有两个标题行水平运行,因此在第三行中开始垂直标题行 <tr> .

table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
<table style="width:50%">
<tr>
<th colspan="2" rowspan="2"></th>
<th colspan="17">Weight, in Kg</th>
</tr>
<tr>
<th>40</th>
<th>45</th>
<th>50</th>
<th>55</th>
<th>60</th>
<th>65</th>
<th>70</th>
<th>75</th>
<th>80</th>
<th>85</th>
<th>90</th>
<th>95</th>
<th>100</th>
<th>105</th>
<th>110</th>
</tr>
<tr>
<th rowspan="11">Height, in cm</th>
<th>160</th>
<td>15</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>35</td>
<td>37</td>
<td>39</td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<th>165</th>
<td>14</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>34</td>
<td>36</td>
<td>38</td>
<td>40</td>
</tr>
<tr>
<th>170</th>
<td>13</td>
<td>15</td>
<td>17</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>24</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>36</td>
<td>38</td>
</tr>
<tr>
<th>175</th>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>35</td>
</tr>
<tr>
<th>180</th>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
<td>33</td>
</tr>
<tr>
<th>185</th>
<td>11</td>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
</tr>
<tr>
<th>190</th>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
</tr>
<tr>
<th>195</th>
<td>10</td>
<td>11</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<th>200</th>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>26</td>
<td>27</td>
</tr>
</table>

当您说“填充”时,我将其理解为 Wight 两侧到单元格边界的空白区域,单位为千克。如果是这样的话:

  1. 增加字体大小,这可能看起来很难看。
  2. 增加letter spacing , letter-spacing: 0.25em; ,这可能看起来很丑。

如果您在谈论 100105110 列中数字后的空格,您可以在上面执行,但我建议让所有列的宽度相同,然后将所有数字居中以使所有内容均等。

请注意,使用这种方法,三位数的空格比两位数的空格少。

table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
th,
td {
min-width: 1.85rem;
}
<table style="width:50%">
<tr>
<th colspan="2" rowspan="2"></th>
<th colspan="17">Weight, in Kg</th>
</tr>
<tr>
<th>40</th>
<th>45</th>
<th>50</th>
<th>55</th>
<th>60</th>
<th>65</th>
<th>70</th>
<th>75</th>
<th>80</th>
<th>85</th>
<th>90</th>
<th>95</th>
<th>100</th>
<th>105</th>
<th>110</th>
</tr>
<tr>
<th rowspan="11">Height, in cm</th>
<th>160</th>
<td>15</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>35</td>
<td>37</td>
<td>39</td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<th>165</th>
<td>14</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>34</td>
<td>36</td>
<td>38</td>
<td>40</td>
</tr>
<tr>
<th>170</th>
<td>13</td>
<td>15</td>
<td>17</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>24</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>36</td>
<td>38</td>
</tr>
<tr>
<th>175</th>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>35</td>
</tr>
<tr>
<th>180</th>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
<td>33</td>
</tr>
<tr>
<th>185</th>
<td>11</td>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
</tr>
<tr>
<th>190</th>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
</tr>
<tr>
<th>195</th>
<td>10</td>
<td>11</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<th>200</th>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>26</td>
<td>27</td>
</tr>
</table>

或者您可以在列和中心设置特定数量的填充。我个人喜欢上面代码片段的结果。在这里,您可以在数字周围获得一致的空白,同时牺牲相等的列宽。

table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
th,
td {
padding: 0.125rem 0.25rem;
}
<table style="width:50%">
<tr>
<th colspan="2" rowspan="2"></th>
<th colspan="17">Weight, in Kg</th>
</tr>
<tr>
<th>40</th>
<th>45</th>
<th>50</th>
<th>55</th>
<th>60</th>
<th>65</th>
<th>70</th>
<th>75</th>
<th>80</th>
<th>85</th>
<th>90</th>
<th>95</th>
<th>100</th>
<th>105</th>
<th>110</th>
</tr>
<tr>
<th rowspan="11">Height, in cm</th>
<th>160</th>
<td>15</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>35</td>
<td>37</td>
<td>39</td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<th>165</th>
<td>14</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>33</td>
<td>34</td>
<td>36</td>
<td>38</td>
<td>40</td>
</tr>
<tr>
<th>170</th>
<td>13</td>
<td>15</td>
<td>17</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>24</td>
<td>25</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>36</td>
<td>38</td>
</tr>
<tr>
<th>175</th>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>31</td>
<td>32</td>
<td>34</td>
<td>35</td>
</tr>
<tr>
<th>180</th>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
<td>33</td>
</tr>
<tr>
<th>185</th>
<td>11</td>
<td>13</td>
<td>14</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
<td>32</td>
</tr>
<tr>
<th>190</th>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>29</td>
<td>30</td>
</tr>
<tr>
<th>195</th>
<td>10</td>
<td>11</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<th>200</th>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>25</td>
<td>26</td>
<td>27</td>
</tr>
</table>

如果这些都不是您所指的,请澄清。

关于html - 从给定单元格开始 rowspan 和 colspan 并减少 rowspan 的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42791507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com