CSS - Button alignment incorrect
P粉794851975
P粉794851975 2024-02-17 18:30:51
0
1
335

No matter what I do (several hours now), I can't align the <div class="kafelek"> next to each other; the current code looks like this:

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>

I've been trying multiple options but it all ends up being a mess.

It looks like this: Website chaos

I want each of the 8 .kafelek (i.e. buttons) to be perfectly aligned with each other in 1 row and properly centered to align with .pre1 and .pre2

please help;-;

P粉794851975
P粉794851975

reply all(1)
P粉242126786

The button container has a width of 0, which prevents the flexbox from working properly. Adding width solves the problem.

.alignkafel1,
.alignkafel2 {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  width: 60%;
  margin: 0 auto;
}

I added a width of 60% to keep the button roughly aligned with the pre above. Currently, pre has the float property set. Ideally, you want the parent container to enforce the bounds of the page content and avoid using float css properties.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!