Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I get these boxes so they right next to each other instead of having a gap between?

HTML
<section>
  <figure class="number box-1 red" id='1'><div class="float">1</div></figure>
  <figure class="number box-1 black" id='2'><div class="float">2</div></figure>
  <figure class="number box-1 red" id='3'><div class="float">3</div></figure>
</section>


CSS
.red { background: red; 
       color: white;}

.black { background: black; 
         color: white;}

.box-1 { float:left;}

.number { height: 45px;
          width: 34px;}


What I have tried:

I'm not really sure how to adjust the css so the boxes are together.
Posted
Updated 10-Oct-22 16:23pm
v2

1 solution

I think the best solution here, if you're OK with targeting only "modern" browsers (and by that I generally mean anything other than IE) is to use flex:

CSS
.red    { background: red;  color: white;}
.black  { background: black;  color: white;}
.number { height: 45px; width: 34px }

.d-flex {display:flex !important; flex-direction: row; justify-content:flex-start;}
.d-flex figure { margin:0; padding:0;}



HTML
 <section class="d-flex">
  <figure class="number red" id='1'><div class="float">1</div></figure>
  <figure class="number black" id='2'><div class="float">2</div></figure>
  <figure class="number red" id='3'><div class="float">3</div></figure>
</section>


failing that, make sure you set margin:0; padding:0; on your figure elements. They come with standard margins in most browsers, and that's probably what's been the problem.
 
Share this answer
 
Comments
Member 8428760 11-Oct-22 13:20pm    
That worked. Thank you so much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900