简体   繁体   English

如何在 CSS 中将框居中居中?

[英]How to center a box to the center in CSS?

I have created a box using div and have 4 more div inside it:我用div创建了一个盒子,里面还有 4 个div

HTML: HTML:

<div className='main__container'>
        <div className='item'>Image</div>
        <div className='item'>Name</div>
        <div className='item'>Price</div>
        <div className='item'>Quantity</div>
</div>

CSS: CSS:

.main__container {
    position: relative;
    text-align: center;
    margin: 0px auto;
    display: flex;
    background-color: white;
}

.item:not(:last-child) {
    margin-right: 100px;
}

This is the output which I get:这是我得到的输出:

react_error

I want to center the whole box to the center.我想把整个盒子放在中心。 I tried to use margin: 0px auto but it isn't working.我尝试使用margin: 0px auto但它不起作用。

Kindly comment if more information is needed.如果需要更多信息,请发表评论。

perhaps也许

.main__container {
    // other 
    width: max-content;
    margin-left: auto;
    margin-right: auto;
    // other
}

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

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