【问题标题】:Horizontal Center Radio Button in Table表格中的水平居中单选按钮
【发布时间】:2015-12-15 12:06:02
【问题描述】:

我不是在发生什么,但这是我的 HTML;

<tr id='javatbd158311X2059X38315A008' class='array2 answers-list radio-list'>
  <td class="answer_cell_003 answer-item radio-item">
  <label class="hide read" for="answer158311X2059X38315A008-3">Neither agree nor disagree</label>
  <input class="radio" type="radio" name="158311X2059X38315A008" value="3" id="answer158311X2059X38315A008-3" title="Neither agree nor disagree" onclick="checkconditions(this.value, this.name, this.type)" />
  </td>
</tr>

我正在尝试将单选按钮居中对齐,但只是停留在左侧。到目前为止,我已经尝试过类似的东西;

table td .radio { text-align:center; margin-left:auto; margin-right:auto; border:1px solid red;}
table tr td { text-align:center; margin-left:auto; margin-right:auto; border:1px solid red;}

它将确认border 属性。并显示一个红色边框,所以我知道它被正确引用了。

我做错了什么?

更新;更多代码

table td .radio { border:1px solid red;display: block;margin:0 auto;}
    table tr td { text-align:center; margin-left:auto; margin-right:auto; border:1px solid red;}
	<table class="question subquestions-list questions-list " summary="An array with sub-question on each line. The answers are contained in the table header. ">
		<colgroup class="col-responses">
		<col class="col-answers" width="50%%" />
	<col class="odd" width="10%" />
	<col class="even" width="10%" />
	<col class="odd" width="10%" />
	<col class="even" width="10%" />
	<col class="odd" width="10%" />
		</colgroup>
		<thead><tr class="dontread">
		<td>&nbsp;</td>
		<th>Strongly agree</th>
		<th>Agree</th>
		<th>Neither agree nor disagree</th>
		<th>Disagree</th>
		<th>Strongly disagree</th>
	</tr></thead>
		
	<tbody>
	
		<tr id='javatbd158311X2059X38315A008' class='array2 answers-list radio-list'>
		<th class="answertext">
	a. One.<input type="hidden" name="java158311X2059X38315A008" id="java158311X2059X38315A008" value="" />
		</th>
				<td class="answer_cell_001 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A008-1">Strongly agree</label>
		<input class="radio" type="radio" name="158311X2059X38315A008" value="1" id="answer158311X2059X38315A008-1" title="Strongly agree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_002 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A008-2">Agree</label>
		<input class="radio" type="radio" name="158311X2059X38315A008" value="2" id="answer158311X2059X38315A008-2" title="Agree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_003 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A008-3">Neither agree nor disagree</label>
		<input class="radio" type="radio" name="158311X2059X38315A008" value="3" id="answer158311X2059X38315A008-3" title="Neither agree nor disagree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_004 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A008-4">Disagree</label>
		<input class="radio" type="radio" name="158311X2059X38315A008" value="4" id="answer158311X2059X38315A008-4" title="Disagree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_005 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A008-5">Strongly disagree</label>
		<input class="radio" type="radio" name="158311X2059X38315A008" value="5" id="answer158311X2059X38315A008-5" title="Strongly disagree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
	</tr>
	
	
		<tr id='javatbd158311X2059X38315A603' class='array1 answers-list radio-list'>
		<th class="answertext">
	b. Two.<input type="hidden" name="java158311X2059X38315A603" id="java158311X2059X38315A603" value="" />
		</th>
				<td class="answer_cell_001 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A603-1">Strongly agree</label>
		<input class="radio" type="radio" name="158311X2059X38315A603" value="1" id="answer158311X2059X38315A603-1" title="Strongly agree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_002 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A603-2">Agree</label>
		<input class="radio" type="radio" name="158311X2059X38315A603" value="2" id="answer158311X2059X38315A603-2" title="Agree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_003 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A603-3">Neither agree nor disagree</label>
		<input class="radio" type="radio" name="158311X2059X38315A603" value="3" id="answer158311X2059X38315A603-3" title="Neither agree nor disagree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_004 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A603-4">Disagree</label>
		<input class="radio" type="radio" name="158311X2059X38315A603" value="4" id="answer158311X2059X38315A603-4" title="Disagree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
				<td class="answer_cell_005 answer-item radio-item">
	<label class="hide read" for="answer158311X2059X38315A603-5">Strongly disagree</label>
		<input class="radio" type="radio" name="158311X2059X38315A603" value="5" id="answer158311X2059X38315A603-5" title="Strongly disagree" onclick="checkconditions(this.value, this.name, this.type)" />
		</td>
	</tr>
	</tbody>
	</table>
    

【问题讨论】:

  • 在您的示例代码中,为.radiotable tr td 添加红色边框有点令人困惑。不同颜色的边框可能会使发生的事情更加清晰。

标签: html css alignment


【解决方案1】:

将单选按钮设为块元素。

display:block

table td .radio { border:1px solid red;display: block;margin:0 auto;}
table tr td { text-align:center; margin-left:auto; margin-right:auto; border:1px solid red;}
<table>
	<tr id='javatbd158311X2059X38315A008' class='array2 answers-list radio-list'>
  <td class="answer_cell_003 answer-item radio-item">
  <label class="hide read" for="answer158311X2059X38315A008-3">Neither agree nor disagree</label>
  
  <input class="radio" type="radio" name="158311X2059X38315A008" value="3" id="answer158311X2059X38315A008-3" title="Neither agree nor disagree" onclick="checkconditions(this.value, this.name, this.type)" />
  </td>
  </tr>
</table>

【讨论】:

  • @mike3875 可能你正在使用float:right 你应该检查一次。
  • 好的,让我们检查一下吧
  • 我检查您的代码并将其复制到 sn-p 中,它与您提供的代码一起使用
  • 和?成功了吗?不要忘记将您的问题回答为@mike3875
【解决方案2】:

给出输入显示块

u can find the code here
 [https://jsfiddle.net/u85mca3d/][1]

【讨论】:

  • 虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-14
相关资源
最近更新 更多