gpt4 book ai didi

css:为什么这些表格的宽度不同?

转载 作者:太空宇宙 更新时间:2023-11-04 05:30:26 25 4
gpt4 key购买 nike

我认为在所有行上使用 100% 会使它们呈现相同的大小,但我显然错了。

a) 我该如何解决这个问题,使所有表格的宽度都与最宽的表格相同?

b)如何为所有行设置固定宽度?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1" />

<title>Evaluaci&oacute;n de Curso</title>


<style type="text/css">

#layouttable tr.row1{ border:0px; width:100%; background-color:#CCCCCC; text-align:center;}
#layouttable tr.row2{ border:0px; width:100%; background-color:#E8E8E8; text-align:center;}
#layouttable tr.row3{ border:0px; width:100%; background-color:#CCCCCC; text-align:center;}




body {
background-color: #CC7722;
margin-left:20%;
margin-right:20%;

padding: 10px 10px 10px 10px;
font-family:sans-serif;

}
</style>

</head>

<body>

<table id="layouttable">

<tr class='row1'><td> &#191;El curso respondi&oacute; a sus expectativas iniciales? </td></tr>
<tr class='row2'><td>&nbsp; &nbsp; Nada(1) / Totalmente(10)</td></tr>
<tr class='row3'><td>
1 <input type="radio" name="respondioExpectativasIniciales" value="1" />
2 <input type="radio" name="respondioExpectativasIniciales" value="2" />
3 <input type="radio" name="respondioExpectativasIniciales" value="3" />
4 <input type="radio" name="respondioExpectativasIniciales" value="4" />
5 <input type="radio" name="respondioExpectativasIniciales" value="5" />
6 <input type="radio" name="respondioExpectativasIniciales" value="6" />
7 <input type="radio" name="respondioExpectativasIniciales" value="7" />
8 <input type="radio" name="respondioExpectativasIniciales" value="8" />
9 <input type="radio" name="respondioExpectativasIniciales" value="9" />
10 <input type="radio" name="respondioExpectativasIniciales" value="10" />
</td></tr>
</table>


<p></p>


<table id="layouttable">

<tr class='row1'><td>Duraci&oacute;n del curso </td></tr>

<tr class='row2'><td>&nbsp; &nbsp; Muy Corta(1) / Excesiva(10) / Ideal (5)</td></tr>

<tr class='row3'><td>
1 <input type="radio" name="duracionDelCurso" value="1" />
2 <input type="radio" name="duracionDelCurso" value="2" />
3 <input type="radio" name="duracionDelCurso" value="3" />
4 <input type="radio" name="duracionDelCurso" value="4" />
5 <input type="radio" name="duracionDelCurso" value="5" />
6 <input type="radio" name="duracionDelCurso" value="6" />
7 <input type="radio" name="duracionDelCurso" value="7" />
8 <input type="radio" name="duracionDelCurso" value="8" />
9 <input type="radio" name="duracionDelCurso" value="9" />
10 <input type="radio" name="duracionDelCurso" value="10" />
</td></tr>

</table>

<p></p>

<table id="layouttable">
<tr class='row1'><td><b>&#191;Qu&eacute; opini&oacute;n le mereci&oacute; el contenido general del curso?</td></tr>

<tr class='row2'><td> &nbsp; &nbsp;Deficiente(1) / Excelente(10)</td></tr>


<tr class='row3'><td>
1 <input type="radio" name="opinionContenido" value="1" />
2 <input type="radio" name="opinionContenido" value="2" />
3 <input type="radio" name="opinionContenido" value="3" />
4 <input type="radio" name="opinionContenido" value="4" />
5 <input type="radio" name="opinionContenido" value="5" />
6 <input type="radio" name="opinionContenido" value="6" />
7 <input type="radio" name="opinionContenido" value="7" />
8 <input type="radio" name="opinionContenido" value="8" />
9 <input type="radio" name="opinionContenido" value="9" />
10 <input type="radio" name="opinionContenido" value="10" />

</td></tr>

</table>


</body>
</html>

现场演示发布(代表 OP)在:http://jsbin.com/ifida

最佳答案

首要的是:您有多个 #layouttable id 的实例。这是无效的,您在给定页面上只能有一个 id 实例。我建议改为将其转换为类名。

顺便说一句,你也没有有效地使用级联(或者,在我看来,正确地),因为你正在为不同的行重复 css 声明,你可以将其修改为:

tr {border: 0; text-align: center; }

tr.row1 {background-color: #ccc; }
/* etc. */

如果您随后为 layouttable 类的表格定义宽度,则所有表格的宽度都相同:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1" />

<title>Evaluaci&oacute;n de Curso</title>


<style type="text/css">

.layouttable {width: 100%; }
tr {border: 0; text-align: center; }

.layouttable tr.row1 {background-color:#CCCCCC; }
.layouttable tr.row2 {background-color:#E8E8E8; }
.layouttable tr.row3 {background-color:#CCCCCC; }




body {
background-color: #CC7722;
margin-left:20%;
margin-right:20%;

padding: 10px 10px 10px 10px;
font-family:sans-serif;

}
</style>

</head>

<body>

<table class="layouttable">

<tr class='row1'><td> &#191;El curso respondi&oacute; a sus expectativas iniciales? </td></tr>
<tr class='row2'><td>&nbsp; &nbsp; Nada(1) / Totalmente(10)</td></tr>
<tr class='row3'><td>
1 <input type="radio" name="respondioExpectativasIniciales" value="1" />
2 <input type="radio" name="respondioExpectativasIniciales" value="2" />
3 <input type="radio" name="respondioExpectativasIniciales" value="3" />
4 <input type="radio" name="respondioExpectativasIniciales" value="4" />
5 <input type="radio" name="respondioExpectativasIniciales" value="5" />
6 <input type="radio" name="respondioExpectativasIniciales" value="6" />
7 <input type="radio" name="respondioExpectativasIniciales" value="7" />
8 <input type="radio" name="respondioExpectativasIniciales" value="8" />
9 <input type="radio" name="respondioExpectativasIniciales" value="9" />
10 <input type="radio" name="respondioExpectativasIniciales" value="10" />
</td></tr>
</table>


<p></p>


<table class="layouttable">

<tr class='row1'><td>Duraci&oacute;n del curso </td></tr>

<tr class='row2'><td>&nbsp; &nbsp; Muy Corta(1) / Excesiva(10) / Ideal (5)</td></tr>

<tr class='row3'><td>
1 <input type="radio" name="duracionDelCurso" value="1" />
2 <input type="radio" name="duracionDelCurso" value="2" />
3 <input type="radio" name="duracionDelCurso" value="3" />
4 <input type="radio" name="duracionDelCurso" value="4" />
5 <input type="radio" name="duracionDelCurso" value="5" />
6 <input type="radio" name="duracionDelCurso" value="6" />
7 <input type="radio" name="duracionDelCurso" value="7" />
8 <input type="radio" name="duracionDelCurso" value="8" />
9 <input type="radio" name="duracionDelCurso" value="9" />
10 <input type="radio" name="duracionDelCurso" value="10" />
</td></tr>

</table>

<p></p>

<table class="layouttable">
<tr class='row1'><td><b>&#191;Qu&eacute; opini&oacute;n le mereci&oacute; el contenido general del curso?</td></tr>

<tr class='row2'><td> &nbsp; &nbsp;Deficiente(1) / Excelente(10)</td></tr>


<tr class='row3'><td>
1 <input type="radio" name="opinionContenido" value="1" />
2 <input type="radio" name="opinionContenido" value="2" />
3 <input type="radio" name="opinionContenido" value="3" />
4 <input type="radio" name="opinionContenido" value="4" />
5 <input type="radio" name="opinionContenido" value="5" />
6 <input type="radio" name="opinionContenido" value="6" />
7 <input type="radio" name="opinionContenido" value="7" />
8 <input type="radio" name="opinionContenido" value="8" />
9 <input type="radio" name="opinionContenido" value="9" />
10 <input type="radio" name="opinionContenido" value="10" />

</td></tr>

</table>


</body>
</html>​

How can I fix this so all tables are the same width as the widest one?

将表格的宽度定义为 100%,这样它就会扩展以填充其父元素提供的水平空间。

How can I set a fixed width for all rows?

表格行总是与其父表格一样宽。除非直到现在我还错过了 xhtml/css 中非常基础的东西。至少我从来没有成功(或故意)尝试为 tr 分配宽度,因为这种理解。

已测试以下内容:

table  {width: 100%; }
tr {width: 10%; }

在 Ubuntu 10.04 上的 Chrome 5.0.375.125 中使用您的 html(以上),我的假设似乎是有效的:该行似乎完全忽略了 width 属性。

关于css:为什么这些表格的宽度不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3498093/

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