我正尝试在网站上发布多篇文章,但是在使用了使用position:absolute将文章居中的代码之后,这些文章现在彼此重叠。我希望文章按顺序垂直堆叠。现在,这些文章完全重叠,如果我有不同的文字,它可能看起来真的很奇怪。我确实需要一些帮助,因此包含了以下代码。
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
h1 {
margin: 0 auto;
font-size: 80px;
text-align: center;
font-family: Bahnschrift;
}
.list-group {
text-align: center;
}
#logo {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
#menubar {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
display: inline;
}
a:focus,
a:hover {
text-decoration: none;
color: white;
}
.post-title:focus,
.post-title:hover {
text-decoration: none;
color: black;
}
a {
display: inline-block;
padding: 15px;
font-family: Bahnschrift;
color: black;
font-size: 20px;
text-decoration: none;
}
#header {
text-align: center;
background-color: #000000;
}
.link {
color: white;
font-size: 20px;
}
/* tell the container's children to float left: */
.float-my-children>* {
float: left;
}
.float-my-children>img {
margin-right: 5px;
width: calc(10% - 5px);
}
.float-my-children>div {
width: 90%;
}
/* this is called a clearfix. it makes sure that the container's children floats are cleared, without using extra markup */
.clearfix {
*zoom: 1/* for IE */
}
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
/* end clearfix*/
article {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
有什么想法可以使文章按顺序垂直堆叠?
答案 0 :(得分:0)
使用flexbox创建水平居中的堆栈非常容易:
html,
body {
margin: 0;
height: 100%;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.item {
border: 1px solid;
}
<div class="container">
<div class="item">foo</div>
<div class="item">bar</div>
<div class="item">baz</div>
</div>