html - CSS 对齐以右对齐表格中的列表

标签 html css html-table html-lists

我在表格中有一个列表,我想将此列表右对齐,这听起来很容易,但由于某些原因不起作用。

这是我的代码:

ul {
  list-style: none;
}
td{
  vertical-align: top;
  width:300px
}
.ri{
  background-color:#AAA;
  text-align:right;
}
<table>
  <tr>
	<td>Equipo</td>
	<td class="ri">
		<ul name="s_truck" style="height: 200px;overflow-y: auto;width: 140px;">
        	<li>
          		<label for="chk_2013035"><input type="checkbox" name="trk[]" id="chk_2013035"> CA046</label>
        	</li>
        	<li>
          		<label for="chk_2013051"><input type="checkbox" name="trk[]" id="chk_2013051"> CA047</label>
        	</li>
        	<li>
          		<label for="chk_2013072"><input type="checkbox" name="trk[]" id="chk_2013072"> CA055</label>
        	</li>
        	<li>
          		<label for="chk_2013031"><input type="checkbox" name="trk[]" id="chk_2013031"> CA056</label>
        	</li>					
		</ul>
	</td>
  </tr>
</table>

在 jsfiddle 上:https://jsfiddle.net/aftc6vq8/7/

为什么不工作?

如何解决?

最佳答案

text-align 不会像 ul

那样对齐 block 级元素

将其显示更改为 inline-block

ul {
  list-style: none;
  display: inline-block;
}

td {
  vertical-align: top;
  width: 300px
}

.ri {
  background-color: #AAA;
  text-align: right;
}
<table>
  <tr>
    <td>Equipo</td>
    <td class="ri">
      <ul name="s_truck" style="height: 200px;overflow-y: auto;width: 140px;">
        <li>
          <label for="chk_2013035"><input type="checkbox" name="trk[]" id="chk_2013035"> CA046</label>
        </li>
        <li>
          <label for="chk_2013051"><input type="checkbox" name="trk[]" id="chk_2013051"> CA047</label>
        </li>
        <li>
          <label for="chk_2013072"><input type="checkbox" name="trk[]" id="chk_2013072"> CA055</label>
        </li>
        <li>
          <label for="chk_2013031"><input type="checkbox" name="trk[]" id="chk_2013031"> CA056</label>
        </li>
      </ul>
    </td>
  </tr>
</table>

关于html - CSS 对齐以右对齐表格中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49429102/

相关文章:

html - 我的 div 容器和这个 div 内的 html 表之间有一个很大的空白空间

html - 具有背景和垂直居中文本的相对 div

html - 隐藏图像直到悬停

html - 如何强制菜单到三 Angular 形边框后面

html - 创建一个包含合并列的 HTML 表格

javascript - jQuery 手机 : refresh after dynamically adding rows to a table with column toggle

html - Bootstrap Navbar 固定宽度,但下拉菜单宽度 100%

javascript - 我的网站页面无法正常工作,但 JS Fiddle 代码可以 - JavaScript 和 HTML 测验

javascript - 当光标隐藏在其他 HTML 元素后面时如何触发 mouseenter 事件?

css - 无法在 Heroku 上加载自定义 CSS