我正在尝试将一些内容框置于我网站的中央,但是每当我尝试将它们与以下内容居中时,它似乎都没有正确居中。那么有谁知道我如何正确地将这些内容框居中并指出正确的方向?谢谢。
'top: 50%;, bottom: 50%; ,transform: translate(-50%, -50%);'
body {
background-color: #323232;
max-width: 960px;
padding: 0;
margin: 0;
font-family: Lato;
}
nav a {
color: #fff;
text-decoration: none;
padding: 20px 25px;
display: inline-block;
}
.fixed-header, .fixed-footer {
background: #333;
color: #fff;
width: 100%;
position: fixed;
text-align: center;
z-index: 10;
background-color: #202020;
}
.fixed-header {
top: 0;
}
.fixed-footer {
bottom: 0;
padding: 20px 0px;
}
.fixed-header a:hover {
color: #c1c1c1;
}
.fixed-footer a {
color: #fff;
font-weight: lighter;
text-decoration: none;
}
.group-content {
max-width: 960px;
text-align: center;
margin-bottom: 4px;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
.group-content h3 {
margin-top: 10px;
font-weight: normal;
font-size: 20px;
color: white;
}
.group-content p {
margin-top: 3px;
font-weight: lighter;
font-size: 20px;
color: white;
}
.content {
width: 30%;
background-color: #202020;
display: flex;
flex-direction: column;
padding: 20px 0 20px 0;
align-items: center;
margin-top: 20px;
}
.content >* {
max-width: 200px;
text-align: center;
margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kumo99.cf</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" href="favicon.ico">
</head>
<body>
<div class="fixed-header">
<nav>
<a href="index.html">HOME</a>
<a href="projects.html">PROJECTS</a>
<a href="about.html">ABOUT</a>
</nav>
</div>
<div class="fixed-footer">
<a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2018</a>
</div>
<div class="group-content">
<div class="content">
<img src="https://i.imgur.com/KPHMNie.png">
<h3>Arma 3: Exile Server</h3>
<p>A project for improving the exile mod.</p>
</div>
<div class="content">
<img src="https://i.imgur.com/KPHMNie.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="https://i.imgur.com/KPHMNie.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="https://i.imgur.com/KPHMNie.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="https://i.imgur.com/KPHMNie.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="https://i.imgur.com/KPHMNie.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
</div>
</body>
</html>
最佳答案
实现此目的的一种方法是将 div 的宽度设置为特定值,即 75%,并将边距设置为“0 auto”,即水平自动居中。在您的情况下,您还需要将 body 宽度设置为 100%,因为这是 div 居中的元素。如果您不希望 body 为 100%,则可以将其设置为您想要的任何宽度并应用“0 auto"margin to your body 以及它在页面上居中。但是,通过这样做,您将不得不尝试使用其他元素来使它们回到现在的位置。 尝试用下面的 css 替换相应的 css...
body {
background-color: #323232;
width:100%;
padding: 0;
margin: 0;
font-family: Lato;
}
.group-content {
max-width: 960px;
text-align: center;
width: 75%;
margin: 75px auto;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
注意 .group-content 中的边距是如何设置为“75px auto”的。这说明了导航栏和页脚,以确保可以通过添加 75 像素的顶部和底部边距来查看 .group-content。
关于html - 如何在不将所有内容居中的情况下对齐组内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48016816/