简体   繁体   中英

Centered Side By Side Boxes

I've been trying to learn how to code TWO side by side boxes, that are centered. I've tried the float: left and all, it just doesn't center it. I need it centered, not one box all the way to the left, and the other to the right. Any help? CSS, not in html please.

.boxcontainer {
  background: none;
  height: 275px;padding: 35px;
}

.Box1 {
  background: rgba(137,20,20);
  border: 1px solid black;
  border-radius: 5px;
  margin: 5px;
  float: center;
  height: 200px;
  width: 200px;
  padding: 15px;
  overflow: auto;
  transition: 0.65s
}

.Box2 {
  background: rgba(137,20,20);
  border: 1px solid black;
  border-radius: 5px;
  margin: 5px;
  float: center;
  height: 200px;
  width: 200px;
  padding: 15px;
  overflow: auto;
  transition: 0.65s
}

i added display:flex;justify-content:center in .boxcontainer

 .boxcontainer {background: none;height: 275px;padding: 35px;display:flex;justify-content:center} .Box1 {background: rgba(137,20,20);border: 1px solid black;border-radius: 5px;margin: 5px;float: center;height: 200px;width: 200px;padding: 15px;overflow: auto;transition: 0.65s} .Box2 {background: rgba(137,20,20);border: 1px solid black;border-radius: 5px;margin: 5px;float: center;height: 200px;width: 200px;padding: 15px;overflow: auto;transition: 0.65s} 
 <div class="boxcontainer"> <div class="Box1"></div> <div class="Box2"></div> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM