gpt4 book ai didi

css - 如何使用 CSS 对齐同一 Div 中的多个元素

转载 作者:太空宇宙 更新时间:2023-11-04 06:18:28 24 4
gpt4 key购买 nike

我试图在一个 div 中水平对齐 4 个元素,但运气不佳。

我已经尝试过 inline-blockfloat leftmargin-rights 到元素,但没有对齐,需要一些帮助.

我的元素:

return(
<div className="counter">
<p className="quantity">quantity: </p>
<button className="counter-btn" id="decrease" onClick={this.decrementCount}>-</button>
<p classname="count">{this.state.count}</p>
<button className="counter-btn" id="increase" onClick={this.incrementCount}>+</button>
</div>
)

我的 CSS:

.counter {
display: inline-block;
border: 1px grey solid;
width: 300px;
flex-direction: column;
margin-bottom: 2em;
}

.counter-btn {
background-color: lightslategrey;
border: none;
border-radius: 25px;
font-size: 1.5em;
color: white;
}

.quantity {
float:left;
padding-right: 2em;
}
.decrease {
/* float:left; */
}
.count {
/* float: left; */
}

它应该是这样的: correct-way

这是它目前的样子: current-way

我能得到对齐方面的帮助吗?

最佳答案

Flex 可以帮助您解决这个问题:

.counter {
display: flex;
align-items: center;
}

关于css - 如何使用 CSS 对齐同一 Div 中的多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com