无论我做什么(现在有几个小时了),我都无法将<div class="kafelek">
并排对齐;当前代码如下所示:
body {
background-color: #003C3D;
}
.header {
text-align: center;
align-content: center;
padding: 20px;
font-family: 'Open Sans';
font-size: 24px;
color: #C3CECB;
}
#headerlogo {
width: 400px;
height: auto;
object-fit: cover;
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
animation: slide-in 1s ease-in-out forwards;
}
@keyframes slide-in {
from {
top: -100px;
}
to {
top: 20px;
}
}
.pre1 {
width: 50%;
text-align: center;
align-content: center;
font-family: 'Open Sans';
font-size: 24px;
color: #C3CECB;
float: left;
}
.pre2 {
width: 50%;
text-align: center;
align-content: center;
font-family: 'Open Sans';
font-size: 24px;
color: #C3CECB;
float: right;
}
.alignkafel1,
.alignkafel2 {
display: flex;
flex-wrap: wrap;
}
.row {
display: flex;
}
.kolumna {
display: inline-block;
width: 48%;
font-family: 'Open Sans';
color: #C3CECB;
text-align: center;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.kolumna:first-child {
margin-right: 0px;
}
.kolumna:last-child {
margin-left: 0px;
}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 800px) {
.kolumna {
width: 100%;
align-content: center;
}
}
kolumna2 {
display: inline-block;
width: 48%;
font-family: 'Open Sans';
color: #C3CECB;
text-align: center;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.kolumna2:first-child {
margin-right: 0px;
}
.kolumna2:last-child {
margin-left: 0px;
}
@media screen and (max-width: 800px) {
.kolumna2 {
width: 100%;
align-content: center;
}
}
.kafelek {
background-color: #006D57;
border-radius: 10px;
text-align: center;
height: 100px;
font-family: 'Open Sans';
font-size: 20px;
color: #C3CECB;
margin: 5px;
margin-top: 50px;
margin-right: 50px;
margin-bottom: 1px;
margin-left: 30px;
display: flex;
align-items: center;
justify-content: center;
}
@media screen and (max-width: 800px) {
.kafelek {
display: flex;
justify-content: center;
}
}
.kafelek:hover {
border: 2px solid #7EDF00;
transition: 0.3s;
cursor: pointer;
}
<div class="header">
<img src="" img id="headerlogo" />
<br /> <br /> Centrum zgłoszeniowe AOK
</div>
<div class="pre1"> Delivery Support </div>
<div class="pre2"> Middle Mile</div>
<div class="alignkafel1">
<div class="kafelek">Koszta Dodatkowe</div>
<div class="kafelek">COMING SOON</div>
<div class="kafelek">COMING SOON</div>
<div class="kafelek">COMING SOON</div>
</div>
<div class="alignkafel2">
<div class="kafelek">COMING SOON</div>
<div class="kafelek">COMING SOON</div>
<div class="kafelek">COMING SOON</div>
<div class="kafelek">COMING SOON</div>
</div>
我一直在尝试多种选择,但最后一切都搞砸了。
它看起来像这样:Messed up website
我希望8个.kafelek
(即按钮)中的每一个都在一行中彼此完全对齐,并且正确居中以与.pre1和.pre2对齐
请帮帮忙;-;
4条答案
按热度按时间oxosxuxt1#
按钮容器的宽度为0,这会使弹性框无法正常工作。添加宽度可以解决此问题。
我添加了一个
60%
的宽度来使按钮大致与上面的pre
对齐。目前pre
已经设置了float
属性。理想情况下,您需要一个父容器来强制页面内容的边界,并避免使用float
css属性。d4so4syb2#
在alignkafel1&2中,设置align-items和justify content属性,以控制作为flex项的按钮的对齐方式。
pftdvrlh3#
我删除了
.alignkafel1
和.alignkafel2
类,并将它们替换为一个带有CSSFlex
的.alignkafel
类。flex-direction: row
属性用于.alignkafel
类,以提供所需的布局。我还从代码中删除了未使用的CSS类。q9rjltbz4#
我修复了你的代码,只要粘贴到你的html和css文件,一切都会正常工作。:D