1

I am trying to make boxes to list upcoming events and am having trouble getting them aligned horizontally. I am using Codepen.io, I will link what I have done. I thought makings a second box #two with the exact details as the first box #one and just moving to the right would work, but I do not know why it doesn't. I made sure not to nest it within the first box #one and just inside the .container .

https://codepen.io/bibaboy/pen/YzVJWKR

body {
  display: grid;
  background-image: radial-gradient(#3f5efb, #fc466b);
}

.container {
  width: 1500px;
  height: 1000px;
  margin: auto;
  border: 1px double black;
}

#one {
  width: 20%;
  height: 350px;
  margin-left: 10%;
  margin-top: 5%;
  padding: 5px;
  border-radius: 35px;
  background: pink;
  box-shadow: 0 2px 10px 0 #e667b8;
}

#two {
  width: 20%;
  height: 350px;
  margin-left: 40%;
  margin-top: 10%;
  padding: 5px;
  border-radius: 35px;
  background: pink;
  box-shadow: 0 2px 10px 0 #e667b8;
}

#header1 {
  font-size: 40px;
  color: #477ced;
  text-align: center;
  text-shadow: 1px 1px black;
}

#p1 {
  font-size: 25px;
  color: black;
  text-align: center;
}
<div class="container">

  <div id="one">
    <p id="header1">September 15 2021</p>
    <hr>
    <p id="p1"> We will be holding a conference for blahblah company in the <b>7th floor of the IBC Bank building</b>.</p>
  </div>

  <div id="two">
    <p id="header1"> Hello Hello </p>
  </div>

</div>
bibaboy
  • 11
  • 1

1 Answers1

0

You could use flexbox for something like this:

https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox

I think this solves the problem your having. I gave the divs with id "one" and "two" a generic class of "box", and removed the margin. Then I added the following flex styles to the container class:

display: flex;

align-items: center;

justify-content: space-around;

display: flex; makes the container into flex container, align-items: center; centers the items vertically, and justify-content: space-evenly; puts the same amount of space on both sides of each item.

<div class="container">

  <div class="box">
    <p id="header1">September 15 2021</p>
    <hr>
    <p id="p1"> We will be holding a conference for blahblah company in the <b>7th floor of the IBC Bank building</b>.</p>
  </div>

  <div class="box">
    <p id="header1"> Hello Hello </p>
  </div>

</div>
body {
  display: grid;
  background-image: radial-gradient(#3f5efb, #fc466b);
}

.container {
  width: 1500px;
  height: 1000px;
  margin: auto;
  border: 1px double black;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

.box {
  width: 20%;
  height: 350px;
  padding: 5px;
  border-radius: 35px;
  background: pink;
  box-shadow: 0 2px 10px 0 #e667b8;
}

#header1 {
  font-size: 40px;
  color: #477ced;
  text-align: center;
  text-shadow: 1px 1px black;
}

#p1 {
  font-size: 25px;
  color: black;
  text-align: center;
}
Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
iltg
  • 51
  • 4
  • Yes thank you! Now that they are centered at least, I can continue to mess around with the code to position more on certain areas of the display. Thank you very much! – bibaboy Aug 07 '21 at 06:02