简体   繁体   English

文本未在容器底部对齐

[英]Text not aligned at the bottom of the container

In this example, the price text is aligned at the top of the container, I want it to be aligned at the bottom of it, like at the baseline在这个例子中,价格文本在容器的顶部对齐,我希望它在容器的底部对齐,就像在基线一样

 .options { margin-top: auto; background: #ffaaff; flex: 1 1 100%; display: flex; justify-content: space-between; line-height: 1; }.money { display: block; }.cart-price { display: block; }
 <div class="options"> <div class="price"> <span class="cart-price"> <span class="money">$49.50</span> </span> </div> <div> <button>Decrease</button> <span >2</span> </div> </div>

You can fix it by adding display: flex and align-items: end to the .price div.您可以通过将display: flexalign-items: end添加到.price div 来修复它。 Read more about flexbox (and align-items ) at MDN . 在 MDN阅读更多关于 flexbox(和align-items )的信息。

.price {
    display: flex;
    align-items: end;
}

 .options { margin-top: auto; background: #ffaaff; flex: 1 1 100%; display: flex; justify-content: space-between; line-height: 1; }.money { display: block; }.cart-price { display: block; }.price { display: flex; align-items: end; }
 <div class="options"> <div class="price"> <span class="cart-price"> <span class="money">$49.50</span> </span> </div> <div> <button>Decrease</button> <span>2</span> </div> </div>

The price class should have price class应该有

align-self: flex-end;

which will align the div with price class vertically at the end of the flex.这将使 div 与 flex 末端的价格 class 垂直对齐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM