css - div 中的文本与具有表格单元格显示属性的图像对齐

标签 css html typescript ionic-framework

我想在 div 容器顶部制作文本,但图像阻止了这一点。我可能已经审查了 div 的使用可能是什么?

这是csshtmltypescript代码:

<div *ngFor="let sh of items" style="border: 1px solid; width: 100%; display:table; text-align: center;">
          <div>
            <div style=" width: 20%; display:table-cell">
                <span>{{sh.product.description}}</span>
            </div>
            <div style=" width: 20%; display:table-cell">{{sh.product.price}}</div>
            <div style=" width: 20%; display:table-cell">{{sh.count}}</div>
            <div style=" width: 20%; display:table-cell">{{sh.count * sh.product.price}}</div>
            <div style=" width: 20%; display:table-cell">
              <img src={{sh.product.picture}} style="height: 100%;"/>
            </div>
          </div>
        </div>

这是输出:

enter image description here

最佳答案

设置 vertical-align: top; 到你的 div

<div *ngFor="let sh of items" style="border: 1px solid; width: 100%; display:table; text-align: center;">
          <div>
            <div style=" width: 20%; display:table-cell;vertical-align: top;">
                <span>{{sh.product.description}}</span>
            </div>
            <div style=" width: 20%; display:table-cell;vertical-align: top;">{{sh.product.price}}</div>
            <div style=" width: 20%; display:table-cell;vertical-align: top;">{{sh.count}}</div>
            <div style=" width: 20%; display:table-cell;vertical-align: top;">{{sh.count * sh.product.price}}</div>
            <div style=" width: 20%; display:table-cell;vertical-align: top;">
              <img src={{sh.product.picture}} style="height: 100%;"/>
            </div>
          </div>
        </div>

关于css - div 中的文本与具有表格单元格显示属性的图像对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50187434/

相关文章:

javascript - JavaScript 函数后的 Css 属性

JavaFX:按钮边框上的背景溢出

CSS Flexbox 模型和图像宽度

angular - 严格模式 - 将值设置为带有延迟加载组件的 ngComponentOutlet 时类型不兼容

typescript - 为什么 Typescript 不声明未赋值的变量?

html - 结合显示 :flex, 表和文本溢出的问题:省略号

javascript - 动态添加下拉和下拉字段

javascript - 正则表达式为 html 属性加上引号

html - CSS grid + srcset + sizes 适用于多种宽度和屏幕分辨率?

angular - 关于 rxjs observables 的基本问题——如何将数据提供给 observable 'by hand' ?