0

I'm trying to keep these two divs side by side. I've set 50% width for them but still they are under eachother. What's wrong?

div{
  border: 1px solid;
  display: inline-block;
  width: 50%;
}
<form>
  <div>
    two
  </div>
  <div>
    one
  </div>
</form>

I don't want to use flex display. Noted that, it would be ok if I set 49% for the width property, but doesn't look standard to me. Also as you know, that 1px border has nothing to do with the issue.

How can I keep them next to each other? Thanks in advance

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Martin AJ
  • 6,261
  • 8
  • 53
  • 111

1 Answers1

2

There are two issues here:

  1. You need to set a box-sizing so that the width of the element includes the border

  2. You need to remove the newline between the divs since it takes an extra space

div{
  border: 1px solid;
  display: inline-block;
  box-sizing: border-box;
  width: 50%;
}
<form>
  <div>
    two
  </div><!-- you need to remove space here --><div>
    one
  </div>
</form>
Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177