css - 如何垂直对齐列内容并设置适合的列宽?

标签 css html twitter-bootstrap

Visual Studio 2017; ASP.NET 核心 MVC; Razor ; Bootstrap

这是我的 cshtml-file 的一部分:

<table class="table table-striped table-bordered">
    <colgroup>
        <col />
        <col style="width:auto; white-space:nowrap" />
    </colgroup>
    <tbody>
        @foreach (var item in Model) {
            <tr>
                <td style="vertical-align:central">@item.TemplateName</td>
                <td>
                    <div class="btn-group pull-right">
                        <a class="btn btn-default" href="#" title="Редактировать">
                            <span class="glyphicon glyphicon-edit"
                                  aria-hidden="true"></span>
                        </a>
                        <a class="btn btn-default" href="#" title="Копировать">
                            <span class="glyphicon glyphicon-plus-sign"
                                  aria-hidden="true"></span>
                        </a>
                        <a class="btn btn-default" href="#" title="Удалить">
                            <span class="glyphicon glyphicon-remove"
                                  aria-hidden="true"></span>
                        </a>
                    </div>
                </td>
            </tr>
        }
    </tbody>
</table>

结果和我预想的不一样:

enter image description here

我需要第一列的内容垂直居中。我还需要根据其内容调整第二列的宽度。

我怎样才能得到它?

最佳答案

你能看看这个吗 http://plnkr.co/edit/I8XBE1kAG8qd0ivWRDhS?p=preview

vertical-align:middle //align vertically middle

<td style="width:1%;white-space:nowrap">
<div class="btn-group pull-right" style="width: auto;min-width: 120px;">
//to fit column width according to its content.

关于css - 如何垂直对齐列内容并设置适合的列宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651938/

相关文章:

javascript - 上传时人像图像水平翻转

css - 这行 CSS 的作用是什么?

jquery - 更改 Jumbotron 不透明度并使其全宽而不影响字体和按钮

javascript - 检测内联样式左值变化和 div 没有 id

html - 居中 Bootstrap 列

html - 如何避免背景图像自动创建滚动条

javascript - jQuery 自动完成 - 如何为 TextArea 下拉菜单设置 CSS 样式?

jquery - CSS 下拉菜单、z-index、iframe 有问题吗?

twitter-bootstrap - Twitter bootstrap carousel - 使用鼠标滚动更改幻灯片

jquery - 元素中的响应 Bootstrap 轮播多列