gpt4 book ai didi

html - 尝试在包装器 div 中居中对齐元素和 div

转载 作者:行者123 更新时间:2023-11-28 17:30:19 25 4
gpt4 key购买 nike

#wrapper {
display: inline-block;
margin: 0 auto;
width: 100%;
display: -webkit-box; /* This tells the chrome browser to use the tools for flexible boxes */
-webkit-box-orient: horizontal;
-webkit-box-flex: 1;
-webkit-box-align: center;
display: -moz-box;
-moz-box-orient: horizontal;
-moz-box-flex: 1;

}
section {
max-width: 760px;
margin-top: 20px;
background-color: #121516;
border-radius: 50px;
padding: 10px;
box-shadow: 5px 5px 10px 10px #000;
display: -webkit-box; /* This tells the chrome browser to use the tools for flexible boxes */
-webkit-box-orient: vertical;
-webkit-box-flex: 2;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
order: 2;
text-align: center;
}

aside {
border-radius: 20px;
margin-top: 15px;
padding: 5px;
color: #5F7278;
width: auto;
float: right;
font-size: 85%;
text-align: center;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-flex: 1;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
order: 3;
position: absolute;
}



#left-aside {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-flex: 1;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
order: 1;
max-width: 150px;
}
.box1 {
width: auto;
max-width: 800px;
height: auto;
padding: 16px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 20px;
flex: 1;
margin: 0px;
}

.box2 {
width: auto;
max-width: 300px;
float: left;
margin-left: 40px;
margin-bottom: 40px;
padding: 14px;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 25px;
flex: 1;
}

.box3 {
width: auto;
max-width: 300px;
float: right;
margin-right: 40px;
padding: 14px;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 23px;
flex: 1;
}

.box4 {
width: auto;
padding: 16px;
padding-bottom: 1px;
margin-left: 20px;
margin-bottom: 10px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 22px;
flex: 1;
}

.box4 a {
font-size: 1.2em;
}

.box5 {
width: auto;
margin-top: 20px;
padding: 16px;
margin-bottom: 10px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
flex: 1;
}
.box5 p {
max-width: 500px;
margin: 0 auto;
line-height: 20px;
}
.box5 form {
margin-top: 20px;
}
.box6 {
width: auto;
max-width: 660px;
height: auto;
padding: 16px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 20px;
flex: 1;
margin-left: 40px;
clear: both;
}
<div id="wrapper">  

<div id="left-aside">
Left aside
</div>

<section><!-- Main part of your page -->

<h1>Main Section with two articles</h1>

<article class="first"><!-- Informational section & can use multiple times -->
Article 1


</article>

<!-- Slideshow -->



<article class="second"><!-- Informational section & can use multiple times -->

Article 2



</article>

</section>


<aside>

Aside

</aside>

</div>

我试图将我的元素和 div 在我的包装 div 中居中对齐,我已经尝试过:

text-align: center
margin: 0 auto

但似乎没有一个似乎有效,因为我在我的 css 中使用 moz-box 和 webkit-box,但这些都没有使父级中的子项居中对齐。我这辈子都做不到,我也试过:

justify-content: center
align-items: center

然而,它没有一个在父级中居中对齐,它卡在屏幕的左侧。

请注意,如果我要删除:

display: -moz-box;
display: -webkit-box;

从父元素和子元素开始,我可以很容易地将它们全部对齐,但是我会失去页面的响应能力,我试图让它尽可能跨平台友好。

最佳答案

#wrapper {
display: inline-block;
margin: 0 auto;
width: 100%;
display: -webkit-box; /* This tells the chrome browser to use the tools for flexible boxes */
-webkit-box-orient: horizontal;
-webkit-box-flex: 1;
-webkit-box-align: center;
display: -moz-box;
-moz-box-orient: horizontal;
-moz-box-flex: 1;

}
section {
max-width: 760px;
margin-top: 20px;
background-color: #121516;
border-radius: 50px;
padding: 10px;
box-shadow: 5px 5px 10px 10px #000;
display: -webkit-box; /* This tells the chrome browser to use the tools for flexible boxes */
-webkit-box-orient: vertical;
-webkit-box-flex: 2;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
order: 2;
text-align: center;
}

aside {
border-radius: 20px;
margin-top: 15px;
padding: 5px;
color: #5F7278;
width: auto;
float: right;
font-size: 85%;
text-align: center;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-flex: 1;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
order: 3;
position: absolute;
}



#left-aside {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-flex: 1;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
order: 1;
max-width: 100%;
}
.box1 {
width: auto;
max-width: 800px;
height: auto;
padding: 16px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 20px;
flex: 1;
margin: 0px;
}

.box2 {
width: auto;
max-width: 300px;
float: left;
margin-left: 40px;
margin-bottom: 40px;
padding: 14px;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 25px;
flex: 1;
}

.box3 {
width: auto;
max-width: 300px;
float: right;
margin-right: 40px;
padding: 14px;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 23px;
flex: 1;
}

.box4 {
width: auto;
padding: 16px;
padding-bottom: 1px;
margin-left: 20px;
margin-bottom: 10px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 22px;
flex: 1;
}

.box4 a {
font-size: 1.2em;
}

.box5 {
width: auto;
margin-top: 20px;
padding: 16px;
margin-bottom: 10px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
flex: 1;
}
.box5 p {
max-width: 500px;
margin: 0 auto;
line-height: 20px;
}
.box5 form {
margin-top: 20px;
}
.box6 {
width: auto;
max-width: 660px;
height: auto;
padding: 16px;
border-right: 1px solid #000;
border-radius: 20px;
box-shadow: 15px 15px 15px #000 inset;
line-height: 20px;
flex: 1;
margin-left: 40px;
clear: both;
}
<div id="wrapper">  

<div id="left-aside">
Left aside
</div>

<section><!-- Main part of your page -->

<h1>Main Section with two articles</h1>

<article class="first"><!-- Informational section & can use multiple times -->
Article 1


</article>

<!-- Slideshow -->



<article class="second"><!-- Informational section & can use multiple times -->

Article 2



</article>

</section>


<aside>

Aside

</aside>

</div>

关于html - 尝试在包装器 div 中居中对齐元素和 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36670828/

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